Log4j is a package to output log statements to a variety of output targets.
The log statements can remain in your shipped code without incurring a heavy performance cost.
The logging behavior can be controlled by editing a configuration file (log4j.properties),
without modifying the application.
One of the distinctive features of log4j is the notion of inheritance in loggers.
By using a logger hierarchy it is possible to control which log statements are output at arbitrarily
fine granularity.
This helps reduce the volume of logged output and minimize the cost of logging.
The target of the log output can be a file, an OutputStream, a java.io.Writer, a remote log4j server,
a remote Unix Syslog daemon, or even a NT Event logger among many other output targets.
Log4j has three main components (loggers, appenders and layouts) which works together to enable developers to log messages
according to message type and level, and to control at runtime how these messages are
formatted and where they are reported.
Log4j is distributed at no charge for commercial or non-commercial use.
For more information read the LICENSE.txt file.
More information about log4j can be found at http://logging.apache.org/log4j/docs/index.html
The latest Log4j version can be downloaded from http://logging.apache.org/log4j/docs/download.html
log4j.properties examples.
Information
none
Operating system used
Windows XP Home Edition Version 5.1 SP 2
Software prerequisites
Log4j 1.2.9
Procedure
- Log4j configuration file, example 1:
# ***** Set root logger level to DEBUG and its only appender to A.
log4j.rootLogger=debug, A
# ***** A is set to be a ConsoleAppender.
log4j.appender.A=org.apache.log4j.ConsoleAppender
# ***** A uses PatternLayout.
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
- Log4j configuration file, example 2:
# ***** Set root logger level to WARN and its two appenders to stdout and R.
log4j.rootLogger=warn, stdout, R
# ***** stdout is set to be a ConsoleAppender.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# ***** stdout uses PatternLayout.
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# ***** Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
# ***** R is set to be a RollingFileAppender.
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
# ***** Max file size is set to 100KB
log4j.appender.R.MaxFileSize=100KB
# ***** Keep one backup file
log4j.appender.R.MaxBackupIndex=1
# ***** R uses PatternLayout.
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
|
|