background preloader

Logging

Facebook Twitter

The complete log4j manual - Ceki Gülcü. The complete log4j manual - Ceki Gülcü. Log4j Tutorial : How to send the log messages to a File using Appender | Veera Sundar. Write custom appenders for log4j. Logging is the simple process of printing messages of various types to known places. Logging messages can go to a console, to a file, to a remote monitor, or anywhere else that you find convenient. Think of logging as a sophisticated sibling of: if( debug ) System.out.println("Debugging diagnostic"); Logging has several advantages over simple statements, however. The logging system can add contextual information—filename, line number, and date, for example—to the message automatically. Logging is central to all of my programs. Logging is essential in server-side debugging, where, typically, no console exists, so System.out proves useless.

One of the better logging systems around is the Apache Software Foundation's log4j project. This article will look at how to extend log4j by adding a new appender—the part of the system responsible for actually sending the log messages somewhere. Using log4J Listing 1 demonstrates how to use log4j. Object associated with the current class. ). Listing 1. Log4j. Apache log4j is a Java-based logging utility. It was originally written by Ceki Gülcü and is now a project of the Apache Software Foundation. log4j is one of several Java logging frameworks.

Gülcü has since started the SLF4J and Logback[1] projects, with the intention of offering a successor to log4j. The log4j team has created a successor to log4j with version number 2.0, which is currently in beta release. log4j 2.0 was developed with a focus on the problems of log4j 1.2, 1.3, java.util.logging and logback, and addresses issues which appeared in those frameworks.

In addition, log4j 2.0 offers a plugin architecture which makes it more extensible than its predecessor. log4j 2.0 is not backwards compatible with 1.x versions,[2] although an "adapter" is available. Log level[edit] The following table defines the log levels and messages in log4j, in decreasing order of severity. Configuration of log4j 1.2[edit] Loggers are logical log file names. The actual outputs are done by Appenders. Where.