1

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.

singhp
  • 11
  • 1

1 Answers1

0

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

Community
  • 1
  • 1
Alexandre Santos
  • 8,170
  • 10
  • 42
  • 64