Saturday, May 12, 2007

log4j



The log4j is a very good logging tool for Java programming language. It is very easy to use and  configure.

The stable version of the JAR file can be downloaded from here. Extract the archived file and include the JAR file in your CLASSPATH.

log4j is configured using properties file or XML file. It is a 2 step process to configure log4j. First we set the APPENDER that tells log4j where to output the log messages and second LAYOUTS that sets the format of the output.

Appender

Appender tells log4j where to output the log messages. Following are the appenders available for log4j.

ConsoleAppender appends log events to System.out or System.err. The default target is System.out.
FileAppender appends log events to a file.
DailyRollingFileAppender extends FileAppender so that the underlying file is rolled over at a user chosen frequency.
RollingFileAppender extends FileAppender to backup the log files when they reach a certain size.
WriterAppender appends log events to a Writer or an OutputStream depending on the user's choice.
SMTPAppender sends an e-mail when a specific logging event occurs, typically on errors or fatal errors.
SocketAppender sends LoggingEvent objects to a remote a log server, usually a SocketNode.
SocketHubAppender sends LoggingEvent objects to a set of remote log servers, usually a SocketNodes
SyslogAppender sends messages to a remote syslog daemon.
TelnetAppender is a log4j appender that specializes in writing to a read-only socket.

0 comments: