简体   繁体   中英

How to send logs with different levels to different appenders using log4j2.properties file?

I'm using log4j2 and am trying to have different log messages go to different appenders within the same logger. This case is described exactly in the log4j2 FAQ - but I need to use the log4j2.properties configuration file instead of the XML configuration given in the example.

Another example with an XML configuration file is given here - essentially, I don't know how to specify the lines

<AppenderRef ref = "Console" level ="info"/>
<AppenderRef ref = "hibernateFile" level = "debug"/>

in log4j2.properties syntax.

You can try below syntax -

rootLogger.level = trace
rootLogger.appenderRef.file.ref = file
rootLogger.appenderRef.file.level = DEBUG
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.stdout.level = INFO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM