In log4j tutorial, we saw how to use log4j xml based configuration. But log4j.xml is verbose, so log4j framework provide option to read configuration from properties file too.
在log4j教程中 ,我们了解了如何使用基于log4j xml的配置。 但是log4j.xml是冗长的,因此log4j框架也提供了从属性文件读取配置的选项。
Since properties file don’t have any defined schema to validate, we have to be more careful with it. Today we will see how XML configurations can be converted to properties based configuration.
由于属性文件没有要验证的已定义架构,因此我们必须格外小心。 今天,我们将看到如何将XML配置转换为基于属性的配置。
根记录器 (Root Logger)
Root logger is used when there is no match with a logger. It’s defined like below in XML.
与记录器不匹配时使用根记录器。 它的定义类似于下面的XML。
<root>
<priority value="DEBUG" />
<appender-ref ref="file" />
<appender-ref ref="console" />
</root>
It can be defined in properties file as below.
可以在属性文件中定义如下。
log4j.rootLogger=DEBUG, file, console
The first value in comma separated list is the root logging level value. All other values are appenders.
逗号分隔列表中的第一个值是根日志记录级别值。 所有其他值都是追加器。
Log4j Appenders (Log4j Appenders)
We can have multiple appenders in log4j. Below are two appenders, one for console log