java日志(log)实践

目的

分享实践成果,解决简单的log日志问题


指定log的范围,指定特定类输出至特定目录
#配置文件指定根logger log4j.rootLogger=A #指定类 log4j.logger.classPathA=A log4j.logger.classPathB=A log4j.logger.classPathC=A #指定logger的输出 log4j.appender.A=org.apache.log4j.ConsoleAppender log4j.appender.A.layout=org.apache.log4j.PatternLayout log4j.appender.A.layout.ConversionPattern=%d %5p [%t] %c{1} -%X{aid} %m%n #指定logger的等级 log4j.appender.A.threshold=ALL

【java日志(log)实践】如:指定类com.example.Test所有等级的log输出至控制台,而其他log只输出WARN等级日志
log4j.rootLogger=CONSOLE,A##### CONSOLE appender log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d %5p [%t] %c{1} -%X{aid} %m%n log4j.appender.CONSOLE.threshold=WARN ##### A appender log4j.logger.com.example.TestA=A log4j.logger.com.example.TestB=A log4j.logger.com.example.TestC=A log4j.appender.A=org.apache.log4j.ConsoleAppender log4j.appender.A.layout=org.apache.log4j.PatternLayout log4j.appender.A.layout.ConversionPattern=%d %5p [%t] %c{1} -%X{aid} %m%n log4j.appender.A.threshold=ALL

    推荐阅读