What is the significance of log4j.rootLogger property in log4j.properties file? What happens if I don’t use this property?

Samudra Gupta explains in his book1:

The Logger object is the main object that an application developer uses to log any message. The Logger objects acting within a particular instance of an application follow a parent-child hierarchy.

If you have the following configuration:

log4j.rootLogger=WARN, stdout

This is how the logger hierarchy could end up looking:2

Samudra Gupta continues to explain:

At the top of the hierarchy exists a root logger. The root logger exists outside the scope of any custom logger hierarchy that we may come up with. It always exists as the root logger for all possible logger hierarchies, and it has no namespace. All the other application-specific Logger objects are child objects to the root logger. The parent-child relationship of loggers signifies the dependency of the loggers acting within the same application. A child logger can inherit properties from its parent logger recursively up the tree. Typically, a child logger will inherit the following properties from its parent logger(s):

  • Level: If the child logger has no explicit tree level specified, it will use the level of its closest parent or the first proper level it finds recursively up the hierarchy.
  • Appender: If there is no appender attached to a logger, the child logger uses the appender of its closest parent logger or the first appender it finds recursively up the tree.
  • ResourceBundleResourceBundles are key-value pattern properties files used for the localization of logging messages. A child logger inherits any ResourceBundle associated with its parent logger.


1 Samudra Gupta, Pro Apache Log4j, Second Edition (Berkeley, CA: Apress, 2005), 24-25, ISBN13: 978-1-59059-499-5

2 Dominic Mitchell, Logging in Javahttp://happygiraffe.net/blog/2008/09/03/logging-in-java/, Retrieved 26 May 2014.

Leave a Comment