java util日志属性中何时需要“.level”?
我见过java util日志以多种方式配置。通常,记录器名称使用完全限定的类名。在相应的日志中。属性文件中,我看到了在包级别或类级别以几种不同的方式配置日志级别。例如,要将com.example.MyClass
的loglevel设置为FINE:
- com。实例级别=良好
- com。示例。*=好的
- com。实例MyClass=很好
- com。实例我的班级。级别=良好
这四种变体都有效吗(假设它们在文件后面没有被覆盖)?
其中有哪个选项比其他选项“更正确”吗?
我喜欢java。util。如果不存在.level
,就假设它是日志记录
我试图找到这个配置文件的最终指南,但在 https://docs.oracle.com/javase/8/docs/technotes/guides/logging/overview.html#a1.8这似乎还不够具体
# 1 楼答案
在标准LogManager下,
com.example.* = FINE
和com.example.MyClass = FINE
不会更改级别。键必须以.level
结尾才能更改级别根据LogManager文档:
如果您使用的是LogManager的子类,那么您需要查阅该文档来验证语法
根据文件,它没有。如果你申报的东西没有。它只会被认为是LogManager entry
LogManager属性文件can't create loggers。这意味着您的日志文件必须与代码创建记录器的方式相匹配。例如,如果您的文件使用
com.example.level = FINE
,而您的代码使用com.example.MyClass1
和com.example.MyClass2
作为记录器名称,您将永远不会看到MyClass1或MyClass2切换为FINE,因为the code never created package parent logger。Root是所有命名记录器的父级,因此这是一次更改多个记录器的理想方式。如果需要做任何非常复杂的事情,那么可以使用LogManager支持的config
选项