Академический Документы
Профессиональный Документы
Культура Документы
TRACE, DEBUG, INFO, WARN, ERROR and FATAL are so-called “LEVEL” in
Loggers. To ensure that all loggers can eventually inherit a level, the root logger always
has an assigned level.
<root>
<priority value ="INFO"/>
</root>
In example 1 above, only the root logger is assigned a level. This level value, Proot, is
inherited by the other loggers X, X.Y and X.Y.Z.
In example 2, all loggers have an assigned level value. There is no need for level
inheritance.
In example 3, the loggers root, X and X.Y.Z are assigned the levels Proot, Px and Pxyz
respectively. The logger X.Y inherits its level value from its parent X.
In example 4, the loggers root and X and are assigned the levels Proot and Px
respectively. The loggers X.Y and X.Y.Z inherit their level value from their nearest parent
X having an assigned level.
Attention: In terms of the configuration of the level (the priority property in the element
category) in log4j.xml, only counts the inheritance, rather than the rule declared below.
Appender Additivity
An Example:
<root>
<priority value ="INFO"/>
<appender-ref ref="ASYNC"/>
</root>
<appender name="LEGOBRICKS"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="legoBricks.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ISO8601};hostname;application;%c;%-5p;%m%n"/>
</layout>
</appender>
<appender name=" A-xyz1" …/>
According the above rule table for additivity, the example is the following:
Additivit
Logger Added Output
y Comment
Name Appenders Targets
Flag
The root logger is
anonymous but can be
accessed with the
not
root ASYNC ASYNC Logger.getRootLogger()
applicable
method. There is no
default appender attached
to root.
com.vodafone.germany LEGOBRICK
No appender accumulation
false LEGOBRICKS since the additivity flag is
S
set to false.
No ASYNC. If an ancestor
of logger C, say P, has the
additivity flag set to
false, then C's output will
be directed to all the
appenders in C and it's
ancestors upto and
com.vodafone.germany. LEGOBRICKS including P but not the
d2
A-xyz1 true , A-xyz1
appenders in any of the
ancestors of P.
C:=
com.vodafone.germany.
d2
P:=
com.vodafone.germany
Configuration
BasicConfigurator.configure(); // configuration xml or properties file
are not necessary, The invocation of the BasicConfigurator.configure()
method creates a rather simple log4j setup. This method is hardwired to
add to the root logger a ConsoleAppender. The output will be formatted
using a PatternLayout set to the pattern "%-4r [%t] %-5p %c %x - %m%n".
http://logging.apache.org/log4j/1.2/manual.html
Summery:
1. looking for the log4j.configuration property in system
2. If 1 is not found, then looking for the log4j.xml or log4j.properties in the root
classes directory project/class.
3. If 2 not found, uses BasicConfigurator.configure, PropertyConfigurator.configure
or DOMConfigurator.configure.