Friday, September 26, 2014

Log4J Configurations

Log4J configurations

Log4J Logger is defined via one of two kinds of files: Properties file, XML file.
(Commonly called “log4j.properties” or “log4j.xml”).
Lets see examples of the two:

log4j.properties




log4j.xml





File Location and it’s Hierarchy
The framework has a hierarchy of search for the configuration file, at first it searches an environment variable, if it’s passed to it, if not, it searches in the Java Classpath (So most of the times you’ll find it in some “resources” directory inside the Jar or the WEB-INF in web applications),
And if after that it’s not found, A Configurator creates the configuration as default and runs the application with and error to the console saying that it didn’t find a configuration file.

How Run Log4j with external configuration

You’ll need to pass a variable to you JVM once you run it like this:
Configuration is made the same way for “log4j.xml”.



No comments:

Post a Comment