Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 801
Jessu Avatar asked Mar 16 '11 12:03

Jessu


1 Answers

Sorry! I misunderstood the usage of 'Logback'. I got solution from http://www.mail-archive.com/[email protected]/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.

like image 187
Jessu Avatar answered Sep 19 '22 17:09

Jessu