Question

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)?

Was it helpful?

Solution 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?

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top