- Last Updated on 17 December 2013
log4j is a very popular logging library for Java development. It provides convenient and flexible logging mechanism as well as fast performance.
Putting log4j into your code is pretty easy as it requires minimum of work which mostly involves in configuring the logging system. This article describes the configuration of log4j in details, as well as providing some working examples.
Table of content
Typically, the steps to use log4j in your Java application are as follows:
- Download latest log4j distribution.
- Add log4j’s jar library into your program’s classpath.
- Create log4j’s configuration.
- Initialize log4j with the configuration.
- Create a logger.
- Put logging statements into your code.
You can get a distribution of log4j at: http://logging.apache.org/log4j/1.2/download.html
The latest version of log4j is 1.2.17. Download log4j-1.2.17.zip file and extract the archive into a directory you like. The distribution comes with a lot of stuff: documentation, source code, examples… but the only thing we need is the log4j-1.2.17.jar file – log4j’s JAR library.
Add the log4j-1.2.17.jar into compilation classpath and runtime classpath of your project in order to have your code can be compiled and executed with log4j.
Recommended Book: Pro Apache Log4j
- Next >>