JavaBeat
Log4j Home Articles Tutorials Java Interview Questions & FAQs Java QnA Code Junction

1. Introduction

2. Installation

3. log4j Basic Concepts

4. Logger

5. Appender

6. Layout

7. Using External Configuration Files

Appender

The Appender controls how the logging is output. The Appenders available are (descriptions borrowed from the log4j API http://jakarta.apache.org/log4j/docs/api/index.html):

  1. ConsoleAppender: appends log events to System.out or System.err using a layout specified by the user. The default target is System.out.

  2. DailyRollingFileAppender extends FileAppender so that the underlying file is rolled over at a user chosen frequency.

  3. FileAppender appends log events to a file.

  4. RollingFileAppender extends FileAppender to backup the log files when they reach a certain size.

  5. WriterAppender appends log events to a Writer or an OutputStream depending on the user's choice.

  6. SMTPAppender sends an e-mail when a specific logging event occurs, typically on errors or fatal errors.

  7. SocketAppender sends LoggingEvent objects to a remote a log server, usually a SocketNode.

  8. SocketHubAppender sends LoggingEvent objects to a set of remote log servers, usually a SocketNodes

  9. SyslogAppendersends messages to a remote syslog daemon.

  10. TelnetAppender is a log4j appender that specializes in writing to a read-only socket.

One may also implement the Appender interface to create ones own ways of outputting log statements.

A FileAppender can be created like this:

          FileAppender appender = null;
try {
appender = new FileAppender(new PatternLayout(),"filename");
} catch(Exception e) {}

The constructor in use above is:

FileAppender(Layout layout, String filename) 
Instantiate a FileAppender and open the file designated by filename.

Another useful constructor is:

FileAppender(Layout layout, String filename, boolean append) 
Instantiate a FileAppender and open the file designated by filename.

So that one may choose whether or not to append the file specified or not. If this is not specified, the default is to append.


Sponsors
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Media (2004-2008), India
javabeat | planetoss | links directory | advertise
Copyright (2004 - 2008), JavaBeat