log4j is a reliable, fast and flexible logging framework (APIs) written in Java, which is distributed under the Apache Software License. log4j is a popular logging package written in Java. log4j has been ported to the C, C++, C#, Perl, Python, Ruby, and Eiffel languages. Also it is very easy to configure at run time through its external log4j.xml configuration file.

There are few main logging levels defined in log4j. Also we can define our own level as well. To do that we have to sub-class from the existing levels.

Here I have listed the main levels of the log4j.

Level Description
ALL All levels including custom levels.
DEBUG Designates fine-grained informational events that are most useful to debug an application.
ERROR Designates error events that might still allow the application to continue running.
FATAL Designates very severe error events that will presumably lead the application to abort.
INFO Designates informational messages that highlight the progress of the application at coarse-grained level.
OFF The highest possible rank and is intended to turn off logging.
TRACE Designates finer-grained informational events than the DEBUG.
WARN Designates potentially harmful situations.

There is a standard order of severity of these levels,



log4j and log4j2

Following advantages are there with the new log4j2 over the log4j

  • Community support.
  • Updates.
  • Async Loggers – performance similar to logging switched off.
  • Custom log levels.
  • Automatically reload its configuration upon modification without losing log events while reconfiguring.
  • Java 8-style lambda support for lazy logging.
  • Log4j 2 is garbage-free (or at least low-garbage) since version 2.6.
  • Filtering based on context data, markers, regular expressions, and other components in the Log event. Filters can be associated with Loggers. You can use a common Filter class in any of these circumstances.
  • Plugin Architecture – easy to extend by building custom components.
  • Supported APIs: SLF4J, Commons Logging, Log4j-1.x and java.util.logging.
  • Log4j 2 API separate from the Log4j 2 implementation.
  • Concurrency improvements.
  • Configuration via XML, JSON, YAML, properties configuration files or programmatically.
  • A new plugin system.
  • Support for properties.
  • Support for JSON-based configuration and automatic reloading of its configuration.
  • Performance improvements.

This is just a basic post to give an introduction to the log4j. Keep in touch to get more information about log4j. Thank You!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s