如何使用SLF4J中的不同引用通过LOG4J将日志写入不同的文件?

时间:2015-03-19 03:52:04

标签: java log4j

我正在尝试将日志写入不同的文件;如果我使用logger1,它应该写入我的调试文件,如果我使用logger2,它应该写入我的报告文件夹。

private static  final Logger logger1= LoggerFactory.getLogger("debugLog");
private static  final Logger logger2= LoggerFactory.getLogger("reportsLog");

我的log4j属性文件如下:

    log4j.rootLogger=TRACE, stdout,debugLog,reportsLog
    log4j.logger.debugLog=TRACE,debugLog
    log4j.logger.reportsLog=DEBUG,reportsLog

    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n

    log4j.appender.debugLog=org.apache.log4j.FileAppender
    log4j.appender.debugLog.Threshold=TRACE
    log4j.appender.debugLog.File=C:\\debug.log
    log4j.appender.debugLog.layout=org.apache.log4j.PatternLayout
    log4j.appender.debugLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n

    log4j.appender.reportsLog=org.apache.log4j.FileAppender
    log4j.appender.reportsLog.Threshold=DEBUG
    log4j.appender.reportsLog.File=C:\\reports.log
    log4j.appender.reportsLog.layout=org.apache.log4j.PatternLayout
    log4j.appender.reportsLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n

    log4j.category.debugLogger=TRACE, debugLog
    log4j.additivity.debugLogger=false

    log4j.category.reportsLogger=DEBUG, reportsLog
    log4j.additivity.reportsLogger=false

0 个答案:

没有答案