Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j 2. How get log4j's debug messages?

As far as i understand log4j can handle system property -Dlog4j.debug. If you run your app with it you will get log4j's debug output.

Example: java -Dlog4j.debug -jar test.jar

Is there something similar for log4j 2?

like image 471
Kirill Popov Avatar asked Oct 24 '13 19:10

Kirill Popov


People also ask

How do I know if log4j2 is working?

If the configuration file is found correctly, log4j2 internal status logging can be controlled by setting <Configuration status="trace"> in the configuration file. This will display detailed log4j2-internal log statements on the console about what happens during the configuration process.

What is log4j format message lookup?

Lookups provide a way to add values to the Log4j configuration at arbitrary places. They are a particular type of Plugin that implements the StrLookup interface. Information on how to use Lookups in configuration files can be found in the Property Substitution section of the Configuration page.

Where can I find log4j properties file?

Sample log4j Configuration Files During Content Engine installation, two log4j sample files are placed on the system in the ContentEngine\config\samples\ folder: log4j. properties. client: A Java format file that contains client configuration settings.

Which log4j objects are responsible for logging messages?

Apache log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as consoles, files, sockets, NT event logs, etc. Each Appender object has different properties associated with it, and these properties indicate the behavior of that object.


2 Answers

Update January 2018:

From Log4j 2.10, this is easy: just run your program with system property log4j2.debug (no value needed; an empty string is fine).


The current (log4j-2.1) documentation on the status logger is a bit confusing. Basically:

  • Until a configuration is found, status logger level can be controlled with system property org.apache.logging.log4j.simplelog.StatusLogger.level.
  • After a configuration is found, status logger level can be controlled in the configuration file with the "status" attribute, for example: <Configuration status="trace">.

UPDATE: the documentation was improved in log4j-2.2.

like image 167
Remko Popma Avatar answered Oct 14 '22 20:10

Remko Popma


It can be confusing, the nearest equivilent of the Log4J 1.x command line argument -Dlog4j.debug is -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=trace which sets the Log4J 2.x "status logger" level to trace and provides detailed output about the logging configuration.

Log4J 1.x allows you to manually specify the location of the configuration file on the command line using -Dlog4j.configuration=file:///var/lib/tomcat7/log4j.xml where the configuration file is located at /var/lib/tomcat7/log4j.xml. In Log4J 2.x there is a subtle difference in the argument -Dlog4j.configurationFile=file:///var/lib/tomcat7/log4j.xml, 'configurationFile' rather than 'configuration'.

Obviously you need to ensure that your configuration file is suitible for the version of Log4J being used, the XML structure differs between 1.x and 2.x.

like image 39
Robert Hunt Avatar answered Oct 14 '22 20:10

Robert Hunt