Skip to content

Logging with Log4j

Ron Gatenio edited this page Apr 1, 2017 · 6 revisions

Log4j is the industry-standard freeware logging tool for Java.

In our project we used Log4j 1.2.17

Logging levels

Log Level Description
FATAL Designates very severe error events
that will presumably lead the application to abort.
ERROR Designates error events that might still allow
the application to continue running.
Usually will be logged in a catch block.
INFO Designates informational messages that highlight the
progress of the application at coarse-grained level.
WARN Designates potentially harmful situations.
DEBUG Designates fine-grained informational events
that are most useful to debug an application.
TRACE Designates finer-grained informational events
than the DEBUG.

Configuration file

Log4j will search for the configuration file in the classpath. It is recommended to place it in the resources folder.

If located in a different directory, add the following VM argument: -Dlog4j.configuration=/path/to/file

Add to maven

Add the following dependency to pom.xml file:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependencies>

Usage example

Log4j Configuration Deep Dive

Learn more about Log4j

Log4j 2

Clone this wiki locally