|
Logger Name |
Assigned
Level
|
Inherited
Level
|
Added Appenders |
Additivity Flag |
Output Targets | Comment |
---|---|---|---|---|---|---|
root | warn |
warn
|
A1 | not applicable | A1 | The root logger is anonymous but can be accessed with the Logger.getRootLogger() method. There is no default appender attached to root. |
x | info |
info
|
A-x | true | A1, A-x | Appenders of "x" and root. |
x.y | none |
info
|
A-xy | false | A1, A-x, A-xy | Appenders in "x.y" , and its parents "x" and root. Log level is info which is inherited from "x" |
x.y.z |
debug
|
debug
|
A-xyz | true | A-xyz | Appenders of "x.y.z". becuase its parent "x.y" addivitity is false, so no more appenders will be added |
When a message is passed to a Logger
, the message is passed through the Logger
's Filter
, if the Logger
has a Filter
set. The Filter
can either accept or reject the message. If the message is accepted, the message is forwarded to the Handler
's set on the Logger
. If no Filter
is set, the message is always accepted.
If a message is accepted by the Filter
, the message is also forwarded to the Handler
's of the parentLogger
's. However, when a message is passed up the hierarchy, the message is not passed through theFilter
's of the parent Logger
's. The Filter
's are only asked to accept the message when the message is passed directly to the Logger
, not when the message comes from a child Logger
.
在log4j中,当某个logger调用关联的appenders进行输出前会先通过synchronized加锁,如下代码所示:
但是在logback中,只会在某个appender要输出日志时,使用ReentrantLock来进行加锁,如下代码所示:
这两者的主要区别不在于ReentrantLock和synchronized,因为最新的JVM中,这两个性能不会相差太多,主要区别在于加锁粒度上,当大并发的情况下,logback会有明显的优势,这个原理和ConcurrentHashMap的分段锁类似。