In the fnlog4j.properties file, a
logger is associated with one or more appenders to enable its log
messages to be written to output media. You can set different kinds
of appenders in the fnlog4j.properties file that
send the log information to the specified output location.
The following table provides a list of all the appenders
being used in the
fnlog4j.properties file along
with brief descriptions and related options. For easier maintenance,
and to reduce any possibility of duplicate log entries, you should
use only one appender.
Table 1. Appenders and descriptionsAppender |
Description and Code Fragments |
ConsoleAppender |
Appends log messages to System.out (the
default) or System.err stream using a layout specified by the user.log4j.appender.CON=org.apache.log4j.ConsoleAppender
Options:
- Threshold=WARN: This appender does not log any messages with priority
lower than the one specified here even if the priority is set lower.
This setting is useful to cut down the number of messages, for example,
in a file log while showing all messages on the console.
- ImmediateFlush=true: The default setting is true, meaning log
messages are not buffered at all. If ImmdiateFlush is set to false,
the last few log events are not written to constant media when problem
occurs with the application.
|
DailyRollingFileAppender |
Logs to a new file when a new day is detected.log4j.appender.TXT=org.apache.log4j.DailyRollingFileAppender
Options:
- Threshold=INFO: This appender does not log any messages with priority
lower than the one specified here even if the priority is set lower.
This setting is useful to cut down the number of messages, for example,
in a file log while showing all messages on the console.
- ImmediateFlush=true: By default, it is set to true, meaning log
messages are not buffered at all. If ImmdiateFlush is set to false,
the last few log events are not written to constant media when problem
occurs with the application.
- File=mylog.txt: File name to log to. You can use ${some_property_key}
(for example, java.home or user.home system properties) to specify
the path in front.
- Append=false: By default, it is set to true, which means append
to the end of the file. false overwrites the file at the start of
each program run.
- MaxFileSize=100 KB: Suffixes can be KB, MB, or GB. Roll the log
file after this size is reached. Append takes a Boolean value that
determines whether output files are overwritten (false) or appended
to (true). Setting the value to false (default) keeps files from growing
unbounded. Use this setting in a development environment where you
make occasional one-time runs. Setting the value to true appends output
to an existing log file on each JVM run. You can limit the size of
the output file by setting the MaxFileSize keyword. For example, if
you configure an output file, cjapi_log.txt,
with MaxFileSize=128 KB and MaxBackupIndex=1, when the file exceeds
128 KB, its contents are automatically moved to cjapi_log.txt.1. Writing continues to an empty cjapi_log.txt file.
- MaxBackupIndex=2: Maintain a maximum of 2 (for example) backup
files. Erases oldest files. 0 means that no backup files are kept.
|
Example appender section with console (CON) and ResourceAppender
(RSCAPD) disabled
#log4j.appender.CON=org.apache.log4j.ConsoleAppender
#log4j.appender.CON.layout=org.apache.log4j.PatternLayout
#log4j.appender.CON.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} [%t] %-5p %c %x %m%n
log4j.appender.TXT=org.apache.log4j.DailyRollingFileAppender
log4j.appender.TXT.layout=org.apache.log4j.PatternLayout
log4j.appender.TXT.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} [%t] %-5p %c %x %m%n
log4j.appender.TXT.File=c:\\pe.txt
log4j.appender.TXT.Append=true