Java logging frameworks

Java logging frameworks

multipleissues
refimprove = June 2008
OR = June 2008
copyedit = June 2008

Java logging frameworks are computer data logging packages for the Java platform.

Logging is a common issue for most development teams. There have been several frameworks developed to ease and standardize the process of logging for the Java platform. This page covers general purpose logging frameworks.

Functionality overview

Logging a message is broken into three major pieces: the Logger, Formatter and the Appender (Handler). The Logger is responsible for capturing the message to be logged, along with certain meta-data like level, and passing that to the logging framework. After receiving the message, the logging framework calls the Formatter on the message. The Formatter accepts an object and formats it for proper logging. The logging framework then hands the formatted message to the appropriate Appender for disposition of the message. This might include displaying on a console, writing to disk, appending to a database, or notification via email.

Simpler logging frameworks, like Java Logging Framework by the Object Guy, combine the logger and the appender together. This makes for simple initial configuration, but less configurable, especially as the project is moved across environments.

Logger

Most frameworks support the notion of a Logger. A Logger is an object that allows the application to log data without regard to where the data is actually logged. The application logs a message in the form of an object or an object and exception. When a Logger is created, it is given a name or an identifier. When logging a message, it is logged at a certain level or priority.

Name

A logger has a name. The name is usually hierarchical, with periods (.) separating the levels. A common naming scheme is to use the name of the class or package that is doing the loggings. Both log4j and the Java API supported defining Handlers higher up the hierarchy.

For example, the logger might be named "com.sun.some.UsefulClass". The handler can be defined for any of the following:

* com
* com.sun
* com.sun.some
* com.sun.some.UsefulClass

Level

The message is logged at a certain level. The common levels are, copied from [http://jakarta.apache.org/commons/logging/guide.html#Message_Priorities_Levels Jakarta Commons Logging] :The logging framework maintains the current logging level for each logger. The logging level can be set more or less restrictive. For example, if the logging level is set to "WARNING", then all messages of that level or higher are logged, ERROR and FATAL.

Formatters or renderers

A Formatter is an object that formats a given object for logging by the Appender. Mostly this consists of taking the object and converting it to a string representation.

Appenders or handlers

The appenders are configured to listen for messages of a certain log level or above. The Appender takes the message it is passed and disposes of the messages. Some message dispositions include:

* display on the console
* write to a file or syslog
* append to a database table
* distribute via JMS
* send via email
* write to a listening socket
* bit-bucket (/dev/null)

Comparing features

ummary

Of the major players, log4j is still the front runner in the Java Logging domainFact|date=June 2008. The log4j project has been around for a long time and has lots of support from the development community. It's simple to implement, yet has powerful tools built in to accomplish most logging tasks. It is also easily extensible to handle proprietary needs.

The Jakarta Commons Logging isn't really a logging framework, but a logging framework wrapper. As such, it requires a logging framework underneath it. It would be useful in an heterogeneous environment where the logging framework is likely to change. However, in most cases, once a suitable logging framework has been chosen, there is little need to change it over the life of the project.

The Java Logging API is also not a logging framework, but standard API for accessing a logging framework. Compatible frameworks can be loaded into JVM and accessed via the API. There is also a logging implementation supplied with the Sun JVM which is the default logging framework access by the API. Many developers confuse this implementation with the Java Logging API.

SLF4J and Logback, both originally written by the same original writer of log4j, are growing potential replacements in particular for log4j and Jakarta Commons Logging.

See also

* SLF4J
* Log4j

External links

* [http://java.sun.com/javase/6/docs/technotes/guides/logging/ Java 6.0 Logging API]
* [http://jakarta.apache.org/commons/logging/ Commons Logging]
* [http://protomatter.sourceforge.net Protomatter]
* [http://www.theobjectguy.com/javalog The Object Guy's Logging Framework]
* [http://java-source.net/open-source/logging Open Source Logging Tools in Java]
* [http://www.developer.com/java/other/article.php/1404951 Logging in Java Applications] article by Thornton Rose


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Java (software platform) — Not to be confused with JavaScript. Java Original author(s) Oracle Corporation Developer(s) James Gosling / Sun Microsystems …   Wikipedia

  • Data logging — is the practice of recording sequential data, often chronologically.Etymology To log is a verb derivative of the noun logbook ; the verb form means to record in a logbook , and may have been coined in the 1820s. The term logbook itself stems from …   Wikipedia

  • Java Et Logiciel Libre — Java est libre et open source (depuis le 13 novembre 2006 voir plus loin), et sa licence à permis l éclosion d un grand nombre d outils libres dans les domaines les plus variés. Sommaire 1 Discussion sur la licence de Java 2 Licence… …   Wikipédia en Français

  • Java et logiciel libre — Java est libre et open source (depuis le 13 novembre 2006 voir plus loin), et sa licence à permis l éclosion d un grand nombre d outils libres dans les domaines les plus variés. Sommaire 1 Discussion sur la licence de Java 2 Licence… …   Wikipédia en Français

  • Java (lenguaje de programación) — Este artículo o sección se encuentra desactualizado. Es posible que la información suministrada aquí haya cambiado o sea insuficiente …   Wikipedia Español

  • Java (technique) — Pour les articles homonymes, voir Java. Java est le nom de marque d une technique informatique développée par Sun Microsystems : la « technologie Java™ ». Java est utilisé dans une grande variété de plates formes depuis les… …   Wikipédia en Français

  • Comparison of Java and C++ — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • Lenguaje de programación Java — Saltar a navegación, búsqueda Java Paradigma: Orientado a objetos Apareció en: 1991 Diseñado por: Sun Microsystems Tipo de dato: Fuerte, Estático Implementacion …   Wikipedia Español

  • Carbonado (Java) — Infobox Software name = Carbonado developer = Amazon Technologies Inc. latest release version = 1.1.3 latest release date = release date|2008|05|29 operating system = Cross platform (JVM) latest preview version = 1.2 BETA1 latest preview date =… …   Wikipedia

  • Apache Logging — ist ein Top Level Projekt der Apache Software Foundation. Mit Hilfe der darin enthaltenen Frameworks kann man sehr einfach in seine Software sehr komplexe Logging Mechanismen einbauen. Log4j ist ein wichtiges Unterprojekt davon und ein De facto… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”