I have a log4j2 logger configuration that basically write all logging of the root logger to a basic logging file. I always use Logger.getRootLogger here.

For some specific events I'd like to log do a different file. How could I configure such a logger in the properties file (eg give it a name that I can then reference from code)?

有帮助吗?

解决方案 2

I finally found out that Markers are the way to route messages:

What is markers in Java Logging frameworks and that is a reason to use them?

其他提示

You can do something like this.

    log4j.appender.transaction=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.transaction.DatePattern='.'yyyy-MM-dd
    log4j.appender.transaction.File=logs/transaction.log
    log4j.appender.transaction.layout=org.apache.log4j.PatternLayout
    log4j.appender.transaction.layout.ConversionPattern=%d{dd MMM yyyy HH\:mm\:ss} %-5p %c{2}\:%L - %m%n
    log4j.appender.transaction.threshold=info

    log4j.logger.transaction=INFO, transaction
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top