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

 

你可能感兴趣的:(log4j,Scheme)