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?

查看:589
本文介绍了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在他的解释中book 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):


  • 级别:如果子记录器没有指定明确的树级别,它将使用其最接近的父级别或它在层次结构中递归找到的第一个适当级别。

  • Appender :如果没有附加到记录器的appender,子记录器使用其最接近的父记录器的appender或第一个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,Second Edition (Berkeley,CA: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天全站免登陆