„Apache Log4j” változatai közötti eltérés

A Wikipédiából, a szabad enciklopédiából
Tartalom törölve Tartalom hozzáadva
Új oldal, tartalma: „{{Szoftver infobox | név = Apache log4j | fejlesztő = Apache Software Foundation | operációs rendszer = multi-platform …”
Címke: HTML-sortörés
(Nincs különbség)

A lap 2013. április 8., 13:20-kori változata

Apache log4j

FejlesztőApache Software Foundation
Legfrissebb stabil kiadás2.23.1 (stabil verzió, 2024. március 10.)[1]
Programozási nyelvJava
Operációs rendszermulti-platform
PlatformJava virtuális gép
KategóriaLoggolási eszköz
LicencApache Licenc 2.0
Az Apache log4j weboldala

Sablon:Lowercase

Az Apache log4j egy Java-alapú loggolási segédeszköz. Eredetileg Ceki Gülcü írta, jelenleg az Apache Software Foundation projektje, egyike a számos Java loggolási keretrendszerének.

Gülcü azóta elkezdte az SLF4J-t és Logback projekteket[2], azzal a szándékkal, hogy méltó utódját hozza létre a log4j-nek.

A log4j csapat szintén elkészítette a log4j utódát a 2.0-s verziószámmal, amely jelenleg béta állapotban van. A log4j 2.0 a hangsúlyt a log4j 1.2, 1.3 és java.util.logging és logback problémáira helyezte, megnevezve azokat a kulcskéréseket, amelyek ezekben a keretrendszerekben felmerültek. A log4j 2.0 továbbá egy bővítő modul architektúrát nyújt, amely jobban bővíthetővé teszi elődjénél. A log4j 2.0 nem kompatibilis visszafelé az 1.x-es verziókkal [3], habár egy illesztő program rendelkezésre áll hozzá.

Log szintek

A következő táblázat definiálja a log szinteket és üzeneteket a log4j-ban, fontossági szerint csökkenő sorrenden. A bal oldali oszlop megadja a log szintek megnevezést a log4j-ben, a jobb oldali oszlop pedig egy rövid leírást ad minden log szintről.


A szócikk egy része még lefordítandó. Segíts te is a fordításban!

Szint Leírás
OFF A legmagasabb lehetséges besorolás,melyet a loggolás kikapcsolására szántak.
FATAL Severe errors that cause premature termination. Expect these to be immediately visible on a status console.
ERROR Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console.
WARN Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console.
INFO Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum.
DEBUG Detailed information on the flow through the system. Expect these to be written to logs only.
TRACE Most detailed information. Expect these to be written to logs only. Since version 1.2.12.

Configuration of log4j 1.2

There are three ways to configure log4j: with a properties file, with an XML file and through Java code. 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 multiple outputs; for example to a file locally and to a socket listener on another computer.

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++ function printf. There are also HTMLLayout and XMLLayout formatters for use when HTML or XML formats are more convenient, respectively.

To debug a misbehaving configuration use the Java VM property -Dlog4j.debug which will output to standard out. To find out where a log4j.properties was loaded from inspect getClass().getResource("/log4j.properties") or getClass().getResource("/log4j.xml").

There is also an implicit "unconfigured" configuration of log4j, that of a log4j-instrumented Java application which lacks any log4j configuration. This prints to stdout a warning that the program is unconfigured, and the URL to the log4j web site where details on the warning and configuration may be found. As well as printing this warning, an unconfigured log4j application does not print messages at INFO, DEBUG or TRACE levels -and possibly not higher level messages.

log4j 1.2 példa

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//LOGGER" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration>
    <!-- 
         an appender is an output destination, such as the console or a file;
         names of appenders are arbitrarily chosen
    -->
    <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
        </layout>
    </appender>
 
    <!-- 
         loggers of category 'org.springframework' will only log messages of level "info" or higher;
         if you retrieve Loggers by using the class name (e.g. Logger.getLogger(AClass.class))
         and if AClass is part of the org.springframework package, it will belong to this category
    -->
    <logger name="org.springframework">
        <level value="info"/>
    </logger>

    <!-- 
         everything of spring was set to "info" but for class 
         PropertyEditorRegistrySupport we want "debug" logging 
    -->
    <logger name="org.springframework.beans.PropertyEditorRegistrySupport">
        <level value="debug"/>
    </logger>
 
    <logger name="org.acegisecurity">
        <level value="info"/>
    </logger>
    
    
    <root>
        <!-- 
            all log messages of level "debug" or higher will be logged, unless defined otherwise 
            all log messages will be logged to the appender "stdout", unless defined otherwise 
        -->
        <level value="debug" />
        <appender-ref ref="stdout" />
    </root>
</log4j:configuration>

TTCC

TTCC is a message format used by log4j.[4] TTCC is an acronym for Time Thread Category Component. It uses the following pattern:

 %r [%t] %-5p %c %x - %m%n

Where

Mnemonic Description
%r Used to output the number of milliseconds elapsed from the construction of the layout until the creation of the logging event.
%t Used to output the name of the thread that generated the logging event.
%p Used to output the priority of the logging event.
%c Used to output the category of the logging event.
%x Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event.
%X{key} Used to output the MDC (mapped diagnostic context) associated with the thread that generated the logging event for specified keyExample for
%m Used to output the application supplied message associated with the logging event.
%n Used to output the platform-specific newline character or characters.

Example output
467 [main] INFO org. Apache.log4j.examples. Sort - Exiting main method.

Portolások

  • log4c - A port for C. Log4C is a C-based logging library, released on SourceForge under the LGPL license. For various Unix operating systems the autoconf and automake files are provided. On Windows a Makefile is provided for use with MSVC. Developers may also choose to use their own make system to compile the source, depending on their build engineering requirements. An instance of the log4c library may be configured via three methods: using environment variables, programmatically, or via XML configuration file. Last version is 1.2.1, released in 2007, and the project is no longer actively developed.[5]
  • log4js - A port for JavaScript. Log4js is available under the licence of Apache Software Foundation. One special feature of Log4js is the ability to log the events of the browser remote on the server. Using Ajax it is possible to send the logging events in several formats (XML, JSON, plain ASCII, etc.) to the server to be evaluated there. The following appenders are implemented for log4js: AjaxAppender, ConsoleAppender, FileAppender, JSConsoleAppender, MetatagAppender, and WindowsEventsAppender. The following Layout classes are provided: BasicLayout, HtmlLayout, JSONLayout, and XMLLayout. Last version is 1.1, released in 2008.[6]
  • log4javascript - Another port for JavaScript. log4javascript is a JavaScript logging framework based on the log4j. The latest version is 1.4.2, released in October 2011.[7]
  • Apache Log4net - A port to the Microsoft .NET Framework. The initial work was done by Neoworks and was donated to the Apache Software Foundation in February 2004. The framework is similar to the original log4j while taking advantage of new features in the .NET runtime. Provides Nested Diagnostic Context (NDC) and Mapped Diagnostic Context (MDC). Last version is 1.2.11, released in 2011.[8]
  • log4perl - A Perl port of the widely popular log4j logging package.[9]
  • log4r - A "port" for Ruby. Log4r was inspired by and provides much of the features of the Apache Log4j project, but is not a direct implementation or clone. Aside from superficial similarities, the projects are not related in any way and the code base is completely distinct. Log4r was developed without even looking at the Apache Log4j code.[10]

Lásd még

Sablon:Portal:Infrormatika

Jegyzetek

További információk

Külső hivatkozások