Why Logging

Inserting log statements into your code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is often the case for distributed applications.

On the other hand, some people argue that log statements pollute source code and decrease legibility. (We believe that the contrary is true). In the Java language where a preprocessor is not available, log statements increase the size of the code and reduce its speed, even when logging is turned off. Given that a reasonably sized application may contain thousands of log statements, speed is of particular importance.


Apache log4j is a Java-based logging utility, It is one of several Java logging frameworks. Log4j is a simple and flexible logging framework.

Log4j uses the plugin pattern to configure components. As such, you do not need to write code to create and configure an Appender, Layout, Pattern Converter, and so on. Log4j automatically recognizes plugins and uses them when a configuration references them. You can reference properties in a configuration, Log4j will directly replace them, or Log4j will pass them to an underlying component that will dynamically resolve them. Properties come from values defined in the configuration file, system properties, environment variables, the ThreadContext Map, and data present in the event. Users can further customize the property providers by adding their own Lookup Plugin.

Log4j is a popular logging package written in Java. Log4j has been ported to the C, C++, C#, Perl, Python, Ruby, and Eiffel languages.

The log4j team has created a successor to log4j with version number 2.0.[3] log4j 2.0 was developed with a focus on the problems of log4j 1.2, 1.3, java.util.logging and logback, and addresses issues which appeared in those frameworks. In addition, log4j 2.0 offers a plugin architecture which makes it more extensible than its predecessor. log4j 2.0 is not backwards compatible with 1.x versions,[4] although an "adapter" is available.


     »  Log4j Configuration

     »  Log4j Basic Example

     »  Log4j properties examples

     »  How to create separate log file for package or class