Posts Tagged ‘log4j’

Types of Log Appenders in log4j

June 3, 2009

Types of log appender

An appender specifies where your log messages are written to. There is a wide choice of appenders available. All appenders are direct or indirect subclasses of the AppenderSkeleton. Therefore we can find all options on the following API page:

http://logging.apache.org/log4j/docs/api/org/apache/log4j/AppenderSkeleton.html

The console and the file appender are a subclass of WriterAppender.

Later on, we are going to choose examples for the following appenders.

ConsoleAppender Logs to console
FileAppender Logs to a file
SMTPAppender Logs by email
RollingFileAppender Logs to a file, starts a new file once the max size is reached. (An alternative is the DailyRollingFileAppender which creates on file per day)

But there are as well:

AsyncAppender, JDBCAppender, JMSAppender, LF5Appender, NTEventLogAppender, NullAppender, NullAppender, SMTPAppender, SocketAppender, SocketHubAppender, SyslogAppender, TelnetAppender, DailyRollingFileAppender, RollingFileAppender.

Custom appenders can be created as well. The log4j download comes with a whole bunch of samples in the examples directory.

For more information on log4j, visit the source below.

Source : http://www.laliluna.de/log4j-tutorial.html

Download and Install log4j / Log for Java

May 1, 2009

Log for java aka log4j is a library. Its a small software that need to be downloaded an installed. The installation which I am going to illustrate if for Linux and a similar procedure can be followed for windows. It can be downloaded from the following link –

http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.15/apache-log4j-1.2.15.tar.gz

Download the tar file and extract it using the following command

tar -xvvzf apache-log4j-1.2.15.tar.gz

Move the for apache-log4j-1.2.15 to the a location of your choice. But I recommend you to put it in a folder where you have installed java (say you have moved the extracted the folder to /usr/java/). Now, the jar file log4j is inside the folder. The path should be

/usr/java/apache-log4j-1.2.15/log4j-1.2.15.jar

After this there are two ways to make it recogniseable by you java program. One is you need to set the CLASSPATH. The second and the best alternative is, you could import that jar file. I guess most of you use NetBeans or Eclipse for java programming. So all you need to do is to imort this jar file and it will be recognised by you package. If you want to know how to use logger function, read the following manual

http://logging.apache.org/log4j/1.2/manual.html

%d bloggers like this: