p6spy2.x配置为slf4j-log4j输出日志同时到控制台和文件

spy.properties配置:

     appender = com.p6spy.engine.spy.appender.Slf4JLogger

log4j.properties中配置如下:
##p6spy
log4j.logger.p6spy=info,spyConsole,spyFile
#配置p6spy的日志不重复打印
log4j.additivity.p6spy=false

#配置p6spy打印输出到控制台并定义其格式
log4j.appender.spyConsole = org.apache.log4j.ConsoleAppender
log4j.appender.spyConsole.Target=System.out
log4j.appender.spyConsole.layout = org.apache.log4j.PatternLayout
log4j.appender.spyConsole.layout.ConversionPattern = %m%n

#配置p6spy打印输出到文件并定义其格式
log4j.appender.spyFile = org.apache.log4j.RollingFileAppender
log4j.appender.spyFile.File = logs/spy/spy.log
log4j.appender.spyFile.MaxFileSize = 10MB
log4j.appender.spyFile.layout = org.apache.log4j.PatternLayout
log4j.appender.spyFile.layout.ConversionPattern = %m%n

问题记录:
由于p6spy输出的日志的class的别名为p6spy 所以 log4j.logger.p6spy可指定该类所采取的打印方式

关于日志重复打印问题参考文章:http://www.07net01.com/2015/03/779688.html
log4j.additivity.p6spy=false


关于p6spy基础配置参考上一篇博客:
http://blog.csdn.net/lk_blog/article/details/46288073

你可能感兴趣的:(工具使用)