我使用Logback-Logging-Framework配置了TomEE,我需要将TomEE / Catalina输出记录到额外的 catalina.out 文件中,而通常所有日志记录都会转到应用程序的.log 即可。
我提出了以下配置,但在我的catalina.out文件中仍然是所有的hibernate语句..我如何分离日志语句? 如何仅在单独的文件中记录给定的包?
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://logback.qos.ch/manual/configuration.html -->
<configuration scan="true" scanPeriod="60 seconds">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator" />
<!-- =============================================== -->
<!-- Logging TomEE/Catalina -->
<!-- =============================================== -->
<appender class="ch.qos.logback.core.FileAppender" name="FILE-CATALINA">
<file>${catalina.base}/logs/catalina.out</file>
<encoder>
<pattern>%d %-5p: [%c] %m %rEx{20} %n</pattern>
</encoder>
</appender>
<logger name="org.apache.catalina" level="INFO" additivity="false">
<appender-ref ref="FILE-CATALINA" />
</logger>
<!-- =============================================== -->
<!-- Logging Application -->
<!-- =============================================== -->
<appender class="ch.qos.logback.core.FileAppender" name="FILE-APP">
<file>${catalina.base}/logs/application.log</file>
<encoder>
<pattern>%d %-5p: [%c] %m %rEx{3} %n</pattern>
</encoder>
</appender>
<logger name="org.hibernate" level="INFO" />
<logger name="org.apache" level="INFO" />
<logger name="org.quartz" level="INFO" />
<!-- =============================================== -->
<!-- ROOT Logger -->
<!-- =============================================== -->
<root level="ERROR">
<!-- log packages with INFO and all errors -->
<appender-ref ref="FILE-APP" />
</root>
<root level="OFF">
<!-- only log package org.apache.catalina -->
<appender-ref ref="FILE-CATALINA" />
</root>
</configuration>
现在catalina.out日志仍然有hibernate日志(因为hibernate配置为INFO):
2015-04-30 13:38:24,004 INFO : [org.apache.catalina.startup.Catalina] Initialization processed in 4949 ms
2015-04-30 13:38:24,033 INFO : [**org.apache.catalina**.core.StandardService] Starting service Catalina
2015-04-30 13:38:24,034 INFO : [org.apache.catalina.core.StandardEngine] Starting Servlet Engine: Apache Tomcat (TomEE)/7.0.47 (1.6.0)
2015-04-30 13:38:28,484 INFO : [org.hibernate.annotations.common.Version] HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
2015-04-30 13:38:28,506 INFO : [org.hibernate.Version] HHH000412: Hibernate Core {4.2.8.Final}
答案 0 :(得分:2)
刚想通了:
我删除了第二个根appender(root level =&#34; OFF&#34; ...),并且appender FILE-CATALINA只从配置的appender-ref获取消息(不再有根级消息)。