log4j.properties 文件中 log4j.rootLogger 属性的意义是什么?如果我不使用此属性会怎样? [英] What is the significance of log4j.rootLogger property in log4j.properties file? What happens if I don't use this property?

查看:30
本文介绍了log4j.properties 文件中 log4j.rootLogger 属性的意义是什么?如果我不使用此属性会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

log4j.properties 文件中 log4j.rootLogger 属性的意义是什么?如果我不使用此属性会怎样?

What is the significance of log4j.rootLogger property in log4j.properties file? What happens if I don't use this property?

示例:

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

如果我将此属性设置为 ERROR 模式会发生什么.

What happens if I set this property to ERROR mode.

推荐答案

Samudra Gupta 在他的书中解释了1:

Samudra Gupta explains in his book1:

Logger 对象是应用程序开发人员用来记录任何消息的主要对象.Logger 对象在应用程序的特定实例中起作用,遵循父子层次结构.

The Logger object is the main object that an application developer uses to log any message. The Logger objects acting within a particular instance of an application follow a parent-child hierarchy.

如果您有以下配置:

log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
log4j.logger.com.me.proj2=INFO

这就是记录器层次结构最终的样子:2

This is how the logger hierarchy could end up looking:2

Samudra Gupta 继续解释:

Samudra Gupta continues to explain:

在层次结构的顶部存在一个根记录器.根记录器存在于我们可能提出的任何自定义记录器层次结构的范围之外.它始终作为所有可能的记录器层次结构的根记录器存在,并且它没有命名空间.所有其他特定于应用程序的 Logger 对象都是根记录器的子对象.记录器的父子关系表示在同一应用程序中运行的记录器的依赖关系.子记录器可以在树上递归地从其父记录器继承属性.通常,子记录器将从其父记录器继承以下属性:

At the top of the hierarchy exists a root logger. The root logger exists outside the scope of any custom logger hierarchy that we may come up with. It always exists as the root logger for all possible logger hierarchies, and it has no namespace. All the other application-specific Logger objects are child objects to the root logger. The parent-child relationship of loggers signifies the dependency of the loggers acting within the same application. A child logger can inherit properties from its parent logger recursively up the tree. Typically, a child logger will inherit the following properties from its parent logger(s):

  • Level:如果子 logger 没有指定明确的树级别,它将使用其最近的父级的级别或它在层次结构中递归找到的第一个适当级别.
  • Appender:如果没有附加到记录器的附加器,子记录器使用其最近的父记录器的附加器或它在树上递归找到的第一个附加器.
  • ResourceBundle:ResourceBundles 是用于日志消息本地化的键值模式属性文件.子记录器继承与其父记录器关联的任何 ResourceBundle.
  • Level: If the child logger has no explicit tree level specified, it will use the level of its closest parent or the first proper level it finds recursively up the hierarchy.
  • Appender: If there is no appender attached to a logger, the child logger uses the appender of its closest parent logger or the first appender it finds recursively up the tree.
  • ResourceBundle: ResourceBundles are key-value pattern properties files used for the localization of logging messages. A child logger inherits any ResourceBundle associated with its parent logger.

<小时>

注意事项

1 Samudra Gupta,Pro Apache Log4j,第二版(加州伯克利:Apress,2005),24-25,ISBN13:978-1-59059-499-5

1 Samudra Gupta, Pro Apache Log4j, Second Edition (Berkeley, CA: Apress, 2005), 24-25, ISBN13: 978-1-59059-499-5

2 Dominic Mitchell,Java 登录http://happygiraffe.net/blog/2008/09/03/logging-in-java/,2014 年 5 月 26 日检索.

2 Dominic Mitchell, Logging in Java, http://happygiraffe.net/blog/2008/09/03/logging-in-java/, Retrieved 26 May 2014.

这篇关于log4j.properties 文件中 log4j.rootLogger 属性的意义是什么?如果我不使用此属性会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆