ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
log4j - Wikipedia, the free encyclopedia

log4j

From Wikipedia, the free encyclopedia

Apache log4j
Developed by Apache Software Foundation
Latest release 1.2.15 / August 29, 2007
Written in Java
OS Cross-platform
Genre Logging Tool
License Apache License 2.0
Website logging.apache.org/log4j

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. It is used primarily as a debugging tool. log4j is one of several Java Logging Frameworks.

Ceki Gülcü has since started the SLF4J and Logback projects, with the intention of offering a compatible successor to log4j.

Log4j 1.2 offers six standard logging levels; from highest (coarsest) to lowest (finest):

  • FATAL
  • ERROR
  • WARN
  • INFO
  • DEBUG
  • TRACE

Also, custom logging levels can be added.

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

Contents

[edit] Example configuration

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC
"http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd">
<log4j:configuration>
    <!-- an appender is an output destination, such as e.g. 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 springframework.org package, it will belong to this category -->
    <category name="org.springframework">
        <priority value="info"/>
    </category>
 
    <category name="org.acegisecurity">
        <priority value="info"/>
    </category>
 
    <root><!-- the root category -->
        <!-- all log messages of level debug or more serious will be logged, unless defined otherwise -->
        <!-- all log messages will be logged to the appender 'stdout', unless defined otherwise -->
        <priority value="debug" />
        <appender-ref ref="stdout" />
    </root>
</log4j:configuration>

[edit] 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.

[edit] External links

[edit] Ports


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -