java util 日志记录属性何时需要“.level”?
When is ".level" required in java util logging properties?
我见过 java 以多种方式配置的 util 日志记录。通常完全限定的 class 名称用于记录器名称。在相应的 logging.properties 文件中,我看到以几种不同的方式在包级别或 class 级别配置日志级别。例如,将 com.example.MyClass
的日志级别设置为 FINE:
- com.example.level = 很好
- com.example.* = 很好
- com.example.MyClass = 很好
- com.example.MyClass.level = 很好
所有这四种变体都有效吗(假设它们在文件后面没有被覆盖)?
是否有任何选项比其他选项“更正确”?
如果 java.util.logging 不存在,是否只是假设 .level
?
我试图找到有关此配置文件的权威指南,但停在了
https://docs.oracle.com/javase/8/docs/technotes/guides/logging/overview.html#a1.8 这似乎很不明确。
Do all four of these variants work (assuming they are not overridden later in the file)?
Most of the online tutorials I've seen use the explicit .level suffix...is that preferred (and why)?
在标准的LogManager下,com.example.* = FINE
和com.example.MyClass = FINE
不会改变级别。密钥必须以 .level
结尾才能更改级别。
根据 LogManager 文档:
All properties whose names end with ".level" are assumed to define log levels for Loggers. Thus "foo.level" defines a log level for the logger called "foo" and (recursively) for any of its children in the naming hierarchy. Log Levels are applied in the order they are defined in the properties file. Thus level settings for child nodes in the tree should come after settings for their parents. The property name ".level" can be used to set the level for the root of the tree.
如果您使用的是 LogManager 的子类,则需要查阅该文档以验证语法。
Does java.util.logging just assume .level if its not there?
根据文档,事实并非如此。如果你声明没有 .level 的东西,它只会被认为是 LogManager entry.
Are any of the options "more correct" than the others?
LogManager 属性文件 . This means that your log file must match how the code is creating the loggers. For instance, if your file is using com.example.level = FINE
and your code is using com.example.MyClass1
and com.example.MyClass2
as the logger name you will never see MyClass1 or MyClass2 switch to FINE because the code never created package parent logger。 Root 是所有命名记录器的父级,因此这是一次更改多个记录器的理想方式。如果您需要做任何非常复杂的事情,那么您可以使用 LogManager 支持的 config
选项。
我见过 java 以多种方式配置的 util 日志记录。通常完全限定的 class 名称用于记录器名称。在相应的 logging.properties 文件中,我看到以几种不同的方式在包级别或 class 级别配置日志级别。例如,将 com.example.MyClass
的日志级别设置为 FINE:
- com.example.level = 很好
- com.example.* = 很好
- com.example.MyClass = 很好
- com.example.MyClass.level = 很好
所有这四种变体都有效吗(假设它们在文件后面没有被覆盖)?
是否有任何选项比其他选项“更正确”?
如果 java.util.logging 不存在,是否只是假设 .level
?
我试图找到有关此配置文件的权威指南,但停在了 https://docs.oracle.com/javase/8/docs/technotes/guides/logging/overview.html#a1.8 这似乎很不明确。
Do all four of these variants work (assuming they are not overridden later in the file)?
Most of the online tutorials I've seen use the explicit .level suffix...is that preferred (and why)?
在标准的LogManager下,com.example.* = FINE
和com.example.MyClass = FINE
不会改变级别。密钥必须以 .level
结尾才能更改级别。
根据 LogManager 文档:
All properties whose names end with ".level" are assumed to define log levels for Loggers. Thus "foo.level" defines a log level for the logger called "foo" and (recursively) for any of its children in the naming hierarchy. Log Levels are applied in the order they are defined in the properties file. Thus level settings for child nodes in the tree should come after settings for their parents. The property name ".level" can be used to set the level for the root of the tree.
如果您使用的是 LogManager 的子类,则需要查阅该文档以验证语法。
Does java.util.logging just assume .level if its not there?
根据文档,事实并非如此。如果你声明没有 .level 的东西,它只会被认为是 LogManager entry.
Are any of the options "more correct" than the others?
LogManager 属性文件 com.example.level = FINE
and your code is using com.example.MyClass1
and com.example.MyClass2
as the logger name you will never see MyClass1 or MyClass2 switch to FINE because the code never created package parent logger。 Root 是所有命名记录器的父级,因此这是一次更改多个记录器的理想方式。如果您需要做任何非常复杂的事情,那么您可以使用 LogManager 支持的 config
选项。