# Root logger option log4j.rootLogger=ALL, stdout, A1 log4j.logger.org.apache.jsp=ALL, stdout, A1 # Direct log messages to stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] [%c:%L] - %m%n # LOG4J daily rolling log files configuration log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender log4j.appender.A1.File=logs/file.log log4j.appender.A1.DatePattern='.'yyyy-MM-dd log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] [%c:%L] - %m%n
大多数时候我定义了几个appender ...一个用于Console,另一些用于文件。但大多数时候我使用相同的布局输出。 有没有办法定义默认的?
那样的东西?
log4j.appender.layout=org.apache.log4j.PatternLayout log4j.appender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] [%c:%L] - %m%n
答案 0 :(得分:0)
# Root logger option log4j.rootLogger=ALL, stdout, A1 log4j.logger.org.apache.jsp=ALL, stdout, A1 PATTERN=%d{yyyy-MM-dd HH:mm:ss} [%p] %l - %m%n # Direct log messages to stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=${PATTERN} # LOG4J daily rolling log files configuration log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender log4j.appender.A1.File=logs/file.log log4j.appender.A1.DatePattern='.'yyyy-MM-dd log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=${PATTERN}
似乎这样做的唯一方法是设置变量,因为我已完成PATTERN=%d{yyyy-MM-dd HH:mm:ss} [%p] %l - %m%n