简体   繁体   中英

Can we change log4j logging level based on the content

Can we change log4j logging level based on content. Also, can this change be made at library level. Putting if condition around every log statement is not recommended.

For example, let us assume we are logging the value of String testString.

We want to set log level to info if testString contains futest, else keep it at debug.

You could use a log4j filter ( http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/Filter.html )

Example: Conditional logging with log4j

You could also use MDC (Mapped Diagnostic Context) and just enable the testString to be shown. Provided that the changes to testString are localized.

MDC: http://logback.qos.ch/manual/mdc.html

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