2

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

Ceki
  • 26,753
  • 7
  • 62
  • 71
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
  • Why is the root logger configured twice? – Ceki Aug 23 '12 at 21:17
  • 1
    Possible duplicate of [Send/redirect/route java.util.logging.Logger (JUL) to Logback using SLF4J?](https://stackoverflow.com/questions/6020545/send-redirect-route-java-util-logging-logger-jul-to-logback-using-slf4j) – try-catch-finally Jun 25 '17 at 12:38

1 Answers1

4

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 j.u.l. For MyFaces you want to configure j.u.l. by propagating your logback configuration via LevelChangePropagator.

Ceki
  • 26,753
  • 7
  • 62
  • 71
  • I didn't do that for myfaces explicitly however I believe Myfaces would pick that by itself as the rest of libraries & my application code is doing currently. I can see the logs from other parts of my app. – Rajat Gupta Aug 23 '12 at 21:10
  • Now getting Myfaces logs in my netbeans console but not in the log files yet. Also getting messages like `FINE: PWC4451: File cannot be read C:\dev\Px10App\target\Px10App\WEB-INF\classes\org\apache\myfaces\shared\renderkit\ContentTypeUtils.class` in very bulk numbers in console window for several libraries used in the app. Does that alarm something bad!? This started to appear after adding LevelChangePropagator to config. – Rajat Gupta Aug 23 '12 at 21:27
  • You should use forward slashes to define the file name. I've edited your question to this effect. – Ceki Aug 23 '12 at 21:31
  • Replacing with forward slashes lead to even the other parts of app that wrote logs previously to file to stop writing. – Rajat Gupta Aug 23 '12 at 21:40
  • Backward slashes are interpreted as escape sequences by Java. You must either use double backslashes '\\' or forward slashes '/'. Using a single backslash is always incorrect. – Ceki Aug 23 '12 at 21:42
  • I just retried but can't explain why I'm getting logs written through using \ but not using `/`(forward slash) – Rajat Gupta Aug 23 '12 at 21:46
  • Do you have other configuration file lying around? An old log4j.properties maybe? – Ceki Aug 23 '12 at 21:48
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15740/discussion-between-ceki-and-user01) – Ceki Aug 23 '12 at 21:50