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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值