ALL – Turns on all logging. (MOST SPECIFIC)
FATAL – Severe errors that cause premature termination.
ERROR – Other run time errors or unexpected conditions.
WARN – Other run time situations that are undesirable or unexpected, but not necessarily “wrong”.
INFO – Interesting run time events: start up, shutdown, etc.
DEBUG – Detailed information on the flow through the system.
TRACE – A fine-grained debug message, typically capturing the flow through the application (v 2.x)
OFF – Turns off all logging. (LEAST SPECIFIC)
Suggested Best Practices
DEBUG messages should print to the console, not log files. To accomplish this, messages of level DEBUG can be configured to print to the console, and messages of level INFO and higher can be configured to print to the log files.
Additivity should be disabled (by setting the additivity attribute on the logger to false) to prevent extraneous output to the console and log files.
If desired, special purpose loggers, such as security, performance, etc. can be used to create multiple log files for each application, but that are smaller, and catered to a specific issue type.
The method configureAndWatch() should be invoked in the startup class so that changes to the configuration file will be monitored and implemented without restarting the application.
Capping Log File Size
Log file size can be capped by using the RollingFileAppender which can be configured to back up the log file once it reaches a certain size. You can also set the maximum number of backup files to be kept. To work properly, the apache-log4j-extras dependency with Maven must be added.
In order to see RollingFileAppender in action, refer this post.
Using Different Configuration Files for Different Environments
Different configuration files can be used in the different environments, in conjunction with Maven profiles, to facilitate reducing unnecessary logging statements in QA, Staging, and Production while still providing all of the information in Development. For example, DEBUG messages could be configured to only print to the log file in Development, but not in QA, Staging, or Production. Separate configuration files can be created for each environment such as: log4j-dev.xml, log4j-qa.xml, log4j-stage.xml, and log4j-prod.xml. To associate each configuration file with the correct Maven profile, the line:
<log4j.file> src/main/resources/environment_specific_config_file_name.xml </log4j.file>
can be added to the properties section of each environment’s Maven profile in the pom.xml.
Here is a link to a great article on log4j – log4j