Thursday, September 13, 2012

About log4j.properties

log4j.properties Syntax:
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







































LevelDescription
ALLAll levels including custom levels.
DEBUGDesignates fine-grained informational events that are most useful to debug an application.
ERRORDesignates error events that might still allow the application to continue running.
FATALDesignates very severe error events that will presumably lead the application to abort.
INFODesignates informational messages that highlight the progress of the application at coarse-grained level.
OFFThe highest possible rank and is intended to turn off logging.
TRACEDesignates finer-grained informational events than the DEBUG.
WARNDesignates 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