- Log4j
Infobox Software
name = Apache log4j
caption =
developer =Apache Software Foundation
latest release version = 1.2.15
latest release date = release date|2007|09|29
latest preview version =
latest preview date =
operating system =Cross-platform
programming language = Java
genre =Logging Tool
license =Apache License 2.0
website = [http://logging.apache.org/log4j logging.apache.org/log4j] Apache log4j is a Java-based logging utility. It was originally written byCeki Gülcü and is now a project of theApache Software Foundation . It is used primarily as a debugging tool.log4j is one of severalJava Logging Frameworks .Ceki Gülcü has since started theSLF4J [http://www.slf4j.org/] and [http://logback.qos.ch/ Logback] projects, with the intention of offering a compatible successor to log4j.Log Level
The following table defines the log levels and messages in Log4j, in decreasing order of severity. The left column lists the log level designation in Log4j and the right column provides a brief description of each log level.
Configuration
There are two ways to configure log4j. One is with a properties file and the other is with an
XML file. Within either you can define 3 main components: Loggers, Appenders and Layouts. Configuring logging via a file has the advantage of turning logging on or off without modifying the application that uses log4j. The application can be allowed to run with logging off until there's a problem, for example, and then logging can be turned back on simply by modifying the configuration file.Loggers are logical log file names. They are the names that are known to the Java application. Each logger is independently configurable as to what level of logging (FATAL, ERROR, etc) it currently logs. In early versions of log4j, these were called category and priority, but now they're called logger and level, respectively.
The actual outputs are done by Appenders. There are numerous Appenders available, with descriptive names, such as FileAppender, ConsoleAppender, SocketAppender, SyslogAppender, NTEventLogAppender and even SMTPAppender. Multiple Appenders can be attached to any Logger, so it's possible to log the same information to a file locally and to a socket listener on another computer, for example.
Appenders use Layouts to format log entries. A popular way to format one-line-at-a-time log files is PatternLayout, which uses a pattern string, much like the C /
C++ functionprintf . There are also HTMLLayout and XMLLayout formatters for use whenHTML or XML formats are more convenient, respectively.Example
Log viewer
Apache has another project named Chainsaw which was intended to use log4j generated log files. Chainsaw is a java-based GUI viewer with a lot of functionality. Chainsaw also uses similar configuration file as log4j. Other log viewing tools can be used with log4j too, for example [http://log2web.sf.net/ log2web] , which is opensource and web-based, but has fewer features than Chainsaw, or [http://www.logmx.com LogMX] , which is a commercial log viewer including more features than Chainsaw (even in the free evaluation version).
See also
*
SLF4J
*ChainsawExternal links
* [http://logging.apache.org/log4j/1.2/manual.html Short introduction to log4j]
* [http://logging.apache.org/log4j/ Official log4j Homepage]
* [http://logging.apache.org/log4j/docs/api/index.html log4j Javadocs]
* [http://timarcher.com/?q=node/10 Setting up a log4j Socket Server to Email You Errors From Your Java Programs]
* [http://www.logmx.com LogMX: a commercial, log4j file viewer]Ports
* [http://code.google.com/p/log5j/ log5j] - A 'modern' log4j that supports printf and has additional performance features.
* [http://dclib.sourceforge.net/ dlib C++ library Homepage] - A port for C++
* [http://logging.apache.org/log4cxx/ Log4cxx Homepage] - apache port for C++
* [http://log4cplus.sourceforge.net/ Log4cplus Homepage] - Another port for C++ (outdated)
* [http://log4cpp.sourceforge.net/ Log4cpp Homepage] - Yet another port for C++ (outdated)
* [http://log4plsql.sourceforge.net/ Log4plsql HomePage] ] - A port to the OraclePL/SQL
*Log4c - A port for C
* [http://log4perl.sourceforge.net/ Log4perl] - A port forPerl
*log4js - A port forJavaScript
* [http://docs.python.org/lib/module-logging.html logging] - The official logging module for Python inspired by log4j.
* [http://log4r.sourceforge.net Log4r] - Ruby logging module inspired by log4j
*Log4net - A port to the Microsoft.NET Framework
* [http://logging.apache.org/log4php/ log4php] a port forPHP
* [http://logback.qos.ch logback] a purported successor to log4j, designed by log4j's founder
* [http://www.forestent.com/wiki/Log4sh:Main_Page log4sh] a port for various Unix shells including sh, bash, dash and ksh
* [http://sourceforge.net/projects/log4cocoa/ Log4Cocoa] - A Port for Cocoa
* [http://sourceforge.net/projects/log4d/ Log4D] - A Port for Delphi
Wikimedia Foundation. 2010.