0
votes

I have a Spring Mybatis project that uses logback and slf4j for logging.. It is working fine when I used it in eclipse.. But when I deployed my project(.war) in tomcat.. I cant see the sql executed in log file. Im using postgresql DB and Mybatis ORM.

Jar Version:

logback-classic-1.0.3.jar

logback-core-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 is located in WEB-INF/classes

1
If "THIS IS FOR UNIX RUNTIME", then why does it contain Windows drive letters (C:/logs/...)?Andreas
hi thanks for the reply... the logfile is for unix, I just modified the path since im testing it in windowsuser5934502
will edit to avoid confusion.. thanksuser5934502
And you're sure you deployed the logback.xml file correctly? I mean, you talk about you ,war file, but give no information that might be relevant.Andreas
yes , it is located in this path.. WEB-INF\classes\logback.xml ... other logs printed correctly... I just cant see the sql executeduser5934502

1 Answers

0
votes

I already have the fix for this one. There is nothing wrong with the loggers.. the problem is on the build (ANT) that I am using in creating war file.

I have set the javac debug to true in my build.xml

<javac verbose="false" srcdir="${src.dir}" destdir="${classes.dir}" deprecation="false" debug="true" source="1.6" target="1.6">
            <classpath refid="classpath" />
        </javac>