当前位置: 动力学知识库 > 问答 > 编程问答 >

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?

网友答案:

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.

网友答案:

If you are using JBoss 5.1 and you are having the same problem[logback not writing to file] then add the following in jboss-web.xml.

<class-loading>
    <loader-repository>
        com.hp:classloader=logback-slf4j
        <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
    </loader-repository>
</class-loading>

This should solve your problem.

分享给朋友:
您可能感兴趣的文章:
随机阅读: