问题描述
我在单独的项目中有2个 logback.xml
个文件。一个使用FileAppender将JDBC SQL记录到文件中,另一个使用ConsoleAppender将错误记录到stdout。
I have 2 logback.xml
files in separate projects. One logs JDBC SQL to a file using a FileAppender and the other logs errors to stdout using a ConsoleAppender.
以下是我的每个logback.xml文件。
Here are my logback.xml files for each.
文件记录
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${user.home}/database.log</file>
<append>false</append>
<encoder>
<pattern>%-5relative %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="jdbc" level="OFF" />
<logger name="jdbc.sqlonly" level="debug" />
<root level="info">
<appender-ref ref="FILE" />
</root>
</configuration>
控制台记录
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-5relative %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="jdbc" level="OFF" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>
我正在合并这两个项目,我希望能够继续将信息级SQL记录到文件和STDOUT的错误。
I am merging these two projects and I want to be able to continue logging the info level SQL to the file and the errors to STDOUT.
我已将两个appender添加到 logback.xml
但我不是确定如何处理我的新 logback.xml中的记录器和根标签$>
I have added the two appenders to the logback.xml
but I am not sure what to do with loggers and the root tags in my new logback.xml
.
推荐答案
试试这个:
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${user.home}/database.log</file>
<append>false</append>
<encoder>
<pattern>%-5relative %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-5relative %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="jdbc" level="OFF" />
<logger name="jdbc.sqlonly" level="INFO" additivity="false">
<appender-ref ref="FILE" />
</logger>
<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>
这篇关于logback.xml中的file和stdout appenders的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!