Maven – Logging with slf4j, and ‘logback’, but not creating specified log file which is in configuration. (using maven, jetty)

jettylogbackmavenslf4j

As specified in title I'm using Maven, and Jetty. For logging using SLF4J and Logback. I have 'logback.xml' at 'src/main/resources'.

    <configuration>
        <appender name="STDOUT"
                class="ch.qos.logback.core.ConsoleAppender">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%-4relative [%thread] %-5level %class - %msg%n</pattern>
            </layout>
        </appender>

        <appender name="FILE"
            class="ch.qos.logback.core.FileAppender">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%-4relative [%thread] %-5level %class - %msg%n</pattern>
            </layout>
            <File>myLog.log</File>
        </appender>

        <logger name="org.mortbay">
            <level value="debug" />
        </logger>

        <root>
            <level value="error" />
            <appender-ref ref="STDOUT" />
            <appender-ref ref="FILE" />
        </root>
</configuration>

But my problem is its not creating the file 'myLog.log' if I run/debug the project. What's the solution to get the log file.

Is there any way to get the log file only with SLF4J?

Best Answer

Sorry! I misunderstood the usage of 'Logback'. I got solution from http://www.mail-archive.com/user@slf4j.org/msg00661.html

i.e.

It appears that you have misunderstood the purpose of SLF4J. If you place slf4j-jdk14-1.5.6.jar then slf4j-api will bind with java.util.logging. Logback will not be used. Only if you place logback-core.jar and logback-classic.jar on your class path (but not slf4j-jdk14-1.5.6.jar) will SLF4J API bind with logback. SLF4J binds with one and only one underlying logging API (per JVM launch).

HTH,

Thanks to Ceki Gulcu. Now I can able to get logs in my file.