请问如果设置Log4J才可以使其日志既单独输出又能输出到主日志文件
大家好. 问个比较基础的Log4J的问题.现在是这样; 有个主日志文件, 然后还有一个单独输出某个类的日志文件. 现在发现主日志文件中如果缺少了这个单独的类的日志文件的化, 有时也不太好定位问题. 所以希望这个单独的类的日志文件既可以保持现在的情况单独输出到某个文件, 又可以输出到主日志文件. 尝试了很多方式, 不成功. 麻烦大家帮帮忙, 非常感谢~~
现在的配置是这样的 (精简版):
log4j.rootLogger = INFO,stdout,I
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %c{3}.%M(%L)<%t>- %m%n
# 主日志文件配置
log4j.appender.I = org.apache.log4j.DailyRollingFileAppender
log4j.appender.I.DatePattern = '.'yyyyMMdd
log4j.appender.I.File = /logs/xxx/xxx-info.log
log4j.appender.I.Append=true
log4j.appender.I.layout = org.apache.log4j.PatternLayout
log4j.appender.I.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %p %c{3}.%M(%L)<%t>- %m%n
# 单独输出的某个类的日志文件配置
log4j.logger.com.company.xxx.XXXClass=info,stdout,xxxClass
log4j.additivity.com.company.xxx.XXXClass=false
log4j.appender.xxxClass=org.apache.log4j.DailyRollingFileAppender
log4j.appender.xxxClass.File=/logs/xxx/xxxClass.log
log4j.appender.xxxClass.DatePattern='.'yyyyMMdd
log4j.appender.xxxClass.Append=true
log4j.appender.xxxClass.threshold=DEBUG
log4j.appender.xxxClass.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxClass.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %c{3}.%M(%L)<%t>- %m%n --------------------编程问答-------------------- 你可以为单独输出加一个输出配置,类似于:
### set log levels ###
#log4j.rootLogger = debug , info, stdout , D, E
log4j.rootLogger = info, stdout , D, E
### print to console ###
log4j.appender.info = org.apache.log4j.ConsoleAppender
log4j.appender.info.Target = System.out
log4j.appender.info.layout = org.apache.log4j.PatternLayout
log4j.appender.info.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n
### print to console ###
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{ABSOLUTE} %5p %c{1}:%L - %m%n
### print to log file ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/error.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = ERROR
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [ %t\:%r ] - [ %p ] %m%n
### print to log file ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = logs/stdout.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = INFO
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [ %t\:%r ] - [ %p ] %m%n
补充:Java , Web 开发