我有一个使用logback和slf4j进行日志记录的Spring Mybatis项目。当我在eclipse中使用它时工作正常..但是当我在tomcat中部署我的项目(.war)时...我看不到执行的sql在日志文件中。 我使用postgresql DB和Mybatis ORM。
Jar版本:
的logback经典-1.0.3.jar
的logback核-1.0.3.jar
SLF4J-API-1.6.4.jar
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- =========================== -->
<!-- THIS IS FOR UNIX RUNTIME -->
<!-- =========================== -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<appender name="UNIXFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>/logs/sample/hps-logfile.log</File>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
</layout>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/sample/hps-logfile-%d{yyyy-MM-dd}-%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>2MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="ANALYTICS-UNIX" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>/logs/sample/analytics-logfile.log</File>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
</layout>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/sample/analytics-logfile-%d{yyyy-MM-dd}-%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>2MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<logger name="org.mybatis">
<level value="TRACE"/>
<appender-ref ref="UNIXFILE" />
</logger>
<logger name="net.sf.jasperreports.engine" level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="ANALYTICS-UNIX" />
</logger>
<logger name="analytics" level="DEBUG" additivity="false">
<appender-ref ref="ANALYTICS-UNIX"/>
</logger>
<root level="debug">
<appender-ref ref="STDOUT" />
<appender-ref ref="UNIXFILE" />
</root>
<!-- =========================== -->
<!-- THIS IS FOR UNIX RUNTIME -->
<!-- =========================== -->
</configuration>
logback.xml位于WEB-INF / classes
中答案 0 :(得分:0)
我已经有了解决这个问题的方法。 记录器没有任何问题..问题在于我在创建war文件时使用的构建(ANT)。
我在build.xml
中将javac debug设置为true<javac verbose="false" srcdir="${src.dir}" destdir="${classes.dir}" deprecation="false" debug="true" source="1.6" target="1.6">
<classpath refid="classpath" />
</javac>