log4j-输出多个日志文件
xml配置如下:
<?xml version="1.0" encoding="gb2312" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <!-- 控制台 --> <appender name="stdout" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <!--<param name="ConversionPattern" value="%d [%15t] [%30.30C{1}] [%3L] %6p - %m %n"/>--> <param name="ConversionPattern" value="%d %6p - %m %n"/> </layout> </appender> <!-- 全日志 --> <appender name="LogFile" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="/export/home/logs/clickstream-consumer"/> <param name="Append" value="true"/> <param name="DatePattern" value="'_'yyyy-MM-dd'.log'"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p - %m |||| %l%n"/> </layout> </appender> <!-- Foundation日志文件输出及日志级别 --> <appender name="foundationLogAppender" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="D:\\logs.log"/> <param name="Append" value="true"/> <param name="DatePattern" value="'_'yyyy-MM-dd'.log'"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%m%n"/> </layout> </appender> <logger name="foundationLog"> <level value="INFO"/> <appender-ref ref="foundationLogAppender"/> </logger> <root> <priority value="INFO"/> <appender-ref ref="stdout"/> <appender-ref ref="LogFile"/> </root> </log4j:configuration>
使用方法:
Logger logger = LoggerFactory.getLogger("foundationLog");
这个记录的日志将会输出到:D:\\logs.log
private static final Logger logger = LoggerFactory.getLogger(BaseConsumer.class);
这个记录的是全局日志,日志将会输出到:/export/home/logs/clickstream-consumer
相关推荐
chw0 2020-11-04
sdaq 2020-07-26
MrLiar 2020-07-07
sdaq 2020-06-16
丨Fanny丨Cri 2020-06-13
CXC0 2020-06-08
MrLiar 2020-06-04
丨Fanny丨Cri 2020-06-03
丨Fanny丨Cri 2020-05-17
JavaWinner 2020-05-10
JavaWinner 2020-05-04
CXC0 2020-04-20
CXC0 2020-04-10
丨Fanny丨Cri 2020-02-18
MrLiar 2020-02-16
CXC0 2020-02-09