Following is the syntax of log4j.properties file for an appender X:
[sourcecode language="text"]
# Define the root logger with appender X
log4j.rootLogger = DEBUG, X
# Set the appender named X to be a File appender
log4j.appender.X=org.apache.log4j.FileAppender
# Define the layout for X appender
log4j.appender.X.layout=org.apache.log4j.PatternLayout
log4j.appender.X.layout.conversionPattern=%m%n
[/sourcecode]
log4j.rootLogger - the first element should be the logging level, Second one should be the appender
Logging levels -
TRACE < DEBUG < INFO < WARN < ERROR < FATAL < ALL
Level | Description |
---|---|
ALL | All levels including custom levels. |
DEBUG | Designates fine-grained informational events that are most useful to debug an application. |
ERROR | Designates error events that might still allow the application to continue running. |
FATAL | Designates very severe error events that will presumably lead the application to abort. |
INFO | Designates informational messages that highlight the progress of the application at coarse-grained level. |
OFF | The highest possible rank and is intended to turn off logging. |
TRACE | Designates finer-grained informational events than the DEBUG. |
WARN | Designates potentially harmful situations. |
We have used only one appender FileAppender in our example above. All the possible appender options are:
- AppenderSkeleton
- AsyncAppender
- ConsoleAppender
- DailyRollingFileAppender
- ExternallyRolledFileAppender
- FileAppender
- JDBCAppender
- JMSAppender
- LF5Appender
- NTEventLogAppender
- NullAppender
- RollingFileAppender
- SMTPAppender
- SocketAppender
- SocketHubAppender
- SyslogAppender
- TelnetAppender
- WriterAppender
We have used PatternLayout with our appender. All the possible options are:
- DateLayout
- HTMLLayout
- PatternLayout
- SimpleLayout
- XMLLayout
No comments:
Post a Comment