Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Code Block
#
# Configure the logger to output info level messages into a rolling log file.
#
log4j.rootLogger=INFO, R

#
# Default output file name
#
application.context=tomcat

#
# Configuration for a rolling log file ("tomcat.log").
#
log4j.appender.R=org.apache.log4j.RollingFileAppender
#
# Edit the next line to point to your logs directory.
# The last part of the name is the log file name.
#
log4j.appender.R.File=${catalina.base}/logs/APPLICATION_OUTPUT_FILE.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.MaxFileSize=5036KB
log4j.appender.R.MaxBackupIndex=4

#
# Print the date in ISO 8601 format
#
log4j.appender.R.layout.ConversionPattern=%d %-5p - %m%n

...

where serverName is the tomcat server on which the application has been deployed.

Using Logger

With the above steps all the output coming from a web application is redirected to the output file. In general it is better to send messages to the Logger rather than to System.out or System.err. Using Logger it is possible to control the importance level of a message and via the above configuration files it is possible to control which levels are actually logged.

To use a Logger in your java code you have to create one; it is generally a static object in your project:

Code Block
java
java

public static Logger logger = Logger.getLogger("myApplicationLogger");

To log a message at INFO level:

Code Block
java
java

logger.log(Level.INFO,"My message");

The levels can be:

  • SEVERE (highest value)
  • WARNING
  • INFO
  • CONFIG
  • FINE
  • FINER
  • FINEST (lowest value)