|
A servlet to initialize the Log4j logger.
This servlet sets up a very simple configuration and accepts a few
optional parameters. Three init-params may be specified:
-
logFile: the path of the log file. If the path begins
with a forward slash it is assumed to be an absolute path, otherwise it
is assumed to be a path relative to the context's root. For example:
WEB-INF/log.txt or /var/log/log.txt. If this
parameter is not specified, it defaults to WEB-INF/log.txt
-
level: the log level. Legal values are ALL,
DEBUG, ERROR, FATAL, INFO,
OFF, WARN. Note that these level correspond to the
log levels defined by Log4j. If this parameter is not specified, it
defaults to ERROR.
-
configFile: the path of a properties file containing
Log4j configuration information. Like logFile, if the path
begins with a forward slash it is assumed to be an absolute path,
otherwise it is assumed to be a path relative to the context's root.
This file should follow the conventions described in the Log4j
documentation.
If no init-params are specified, the following configuration is created:
log4j.appender.default=org.apache.log4j.FileAppender
log4j.appender.default.file=WEB-INF/log.txt # logFile
log4j.appender.default.layout=org.apache.log4j.PatternLayout
log4j.appender.default.layout.ConversionPattern=org.apache.log4j.PatternLayout=%d %-5p %c - %m%n
log4j.rootLogger=ERROR,default # level
Specifying logFile and level overrides the properties
indicated above. If configFile is specified, its properties will
be combined with those above, overriding any conflicting properties.
So, as an example, if you wanted to enable DEBUG logging for this class
only and you wanted to override the output format, you could add the
following lines to your configFile:
log4j.rootLogger=OFF
log4j.logger.com.methodhead.servlet.LoggerServlet=DEBUG
log4j.appender.default.layout=org.apache.log4j.PatternLayout
log4j.appender.default.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
|