Log4j 總結(三) log4j 之 Logger

Loggers are named entities. Logger names are case-sensitive and they follow the hierarchical naming rule:

Named Hierarchy
A logger is said to be an ancestor of another logger if its name followed by a dot is a prefix of the descendant logger name. A logger is said to be a parent of a child logger if there are no ancestors between itself and the descendant logger.

For example, the logger named "com.foo" is a parent of the logger named "com.foo.Bar" . Similarly, "java" is a parent of "java.util" and an ancestor of "java.util.Vector" . This naming scheme should be familiar to most developers.

The root logger resides at the top of the logger hierarchy. It is exceptional in two ways:

  1. it always exists,
  2. it cannot be retrieved by name.

This observation had previously led us to choose category as the central concept of the package. However, since log4j version 1.2, Logger class has replaced the Category class.

 

log4j的Logger是大小寫敏感的,且遵從名稱繼承規則.

名稱繼承規則爲:

類似java的package.“com.foo ”爲“com.foo.Bar ”的父類,爲“com.foo.Bar.aeo ”的祖先,在這個繼承關係中,倘若“com.foo.Bar ”不作爲Logger,則“com.foo ”直接爲“com.foo.Bar.aeo ”的父類。log4j的頂級父類爲root.

root永遠存在且不能通過名稱獲取。子類繼承父類的設置。

 

log4j 從1.2版本以後,使用 “Logger ”代替 “Category ” 作爲Logger 的root。

Logger root = Logger.getRootLogger();

Logger的級別爲

TRACE,DEBUG,INFO,WARN,ERROR,FATAL

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章