log4j.xml 2
时间: 2023-08-02 17:14:19 浏览: 137
log4j.xml是Log4j库中的一个配置文件,用于定义日志输出的格式、级别、目的地等。下面是一个简单的log4j.xml配置文件示例:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
```
这个配置文件定义了一个名为"console"的输出目的地,它是一个控制台输出。输出的格式使用了PatternLayout类定义的模式,其中%d表示日期时间、%t表示线程名、%-5p表示日志级别(左对齐,最短5个字符)、%c表示Logger名、%m表示日志消息、%n表示换行符。最后通过<root>标签将日志级别设置为DEBUG,并将输出目的地设置为"console"。这样,DEBUG级别及以上的日志消息就会输出到控制台。
阅读全文
相关推荐












