简体   繁体   中英

Redirecting logs for JUL to logback using SLF4J LevelChangePropagator fails

I'm redirecting all logs meant for JUL to logback using jul-to-slf4j . But it works if I use the SLF4JBridgeHandler approach but I cannot see the logs getting written when I use more performant LevelChangePropagator approach by adding following lines to config files( logback.xml & logback-test.xml ):

<configuration debug="true">
      <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
      .......
</configuration>       

No logs are getting written.

Edit:

Here is what my full config file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
  <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -> %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>c:/dev/logs_test/log_01.log</file>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -> %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="px10" level="TRACE"/>

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

Tried with JSF(Myfaces 2.1.8) App on Glassfish 3.1.1

Have your tried setting the level of JSF (MyFaces) loggers in your logback.xml config?

<configuration debug="false">
  <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>

  <logger name="org.apache.myfaces" level="DEBUG"/>    
</configuration> 

LevelChangePropagator does not do anything unless there level changes to propagate. The fact that logging in other parts of your application work as you expect, only means that those parts are configured correctly for logback, but not necessarily jul For MyFaces you want to configure jul by propagating your logback configuration via LevelChangePropagator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM