5

I'm using log4j 2 for logging and want to turn off the log messages from the library itself, e.g.:

2017-02-20 07:36:38,160 main DEBUG Took 0.001600 seconds to load 0 plugins from package org.apache.logging.log4j.test

I got the following in my log4j2.XML file but I still get DEBUG messages like the one above:

<Logger name="org.apache.logging" level="error" additivity="false">
    <AppenderRef ref="STDOUT" />
</Logger>

This question is not a duplicate of Disabling Log4J Output in Java because I don't want to turn off all output, only the output from the log4j 2 library itself. So I still want my code to generate log output.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
Roland
  • 7,525
  • 13
  • 61
  • 124
  • Possible duplicate of [Disabling Log4J Output in Java](http://stackoverflow.com/questions/571960/disabling-log4j-output-in-java) – Atul Feb 20 '17 at 07:00
  • @Leozeo no, it's not a duplicate, I edited the question to explain why. – Roland Feb 20 '17 at 07:09
  • Did you check http://stackoverflow.com/questions/14891080/how-to-get-selective-logs-from-log4j-properties-file but its related to log4j not log4j 2. – Atul Feb 20 '17 at 07:13

3 Answers3

8

You can control the internal logging Log4j2 prints to the console with the status attribute at the top of the configuration file.

I would recommend that you switch off the verbose debug-level logging but keep the warn and error level logging so you get informed when something goes wrong.

To do this, change the beginning of the configuration file to this:

<Configuration status="WARN">
  ...
Remko Popma
  • 35,130
  • 11
  • 92
  • 114
3

Set logging root level to <Root level="off">

Atul
  • 1,536
  • 3
  • 21
  • 37
0

Be careful if you are migrating from log4j 1.x as I am trying to do. I've correctly configured log4j2 but somehow there was still log4j as inherited dependency (and a inherited configuration) in my project. The side effect of that is that both log4j are able to log, this is pretty annoying and pretty impossible to debug.

giaffa86
  • 708
  • 1
  • 9
  • 22