msgbartop
Various ramblings-on, mostly about Red5
msgbarbottom

18 Sep 08 Logging work-around

I have given up waiting for someone to claim the bounty or produce a fix for the web context logger issue. After much trouble tracking everything down, I have finally “fixed” the logging for web contexts, that is for those of you using the bootstrap method of server start up. The fixed revision is 3068 and its a little rough; meaning I still need to do bit of refactoring. I just wanted to let you all know.

Part 1

Here is what you have to put in your web.xml for each web application to get an individual logger context:

[listener]
[listener-class]org.red5.logging.ContextLoggingListener[/listener-class]
[/listener]


The second thing you must do is rename your logback.xml for each of your web applications, it must be in this form “logback-mywebappname.xml” and be located in the web application classpath. Here is an example of a context logback config file:

[?xml version=”1.0″ encoding=”UTF-8″ ?]
[configuration]
[appender name=”MYAPP” class=”ch.qos.logback.core.FileAppender”]
[File]c:/red5/log/myapp.log[/File]
[Append]false[/Append]
[Encoding]UTF-8[/Encoding]
[BufferedIO]false[/BufferedIO]
[ImmediateFlush]true[/ImmediateFlush]
[layout class=”ch.qos.logback.classic.PatternLayout”]
[Pattern]%date [%thread] %-5level %logger{35} – %msg%n[/Pattern]
[/layout]
[/appender]

[root]
[appender-ref ref=”MYAPP”/]
[/root]

[logger name=”my.package.name”]
[level value=”DEBUG”/]
[/logger]
[/configuration]

You’ll need to replace all the appropriate names with your package and webapp names in addition to all the brackets / braces since WP doesn’t want to play-nice with XML.

Part 2

I’m not completely happy with this fix, but until I absolutely feel the need to override the LoggerFactory, we will need to get our loggers within our Red5 applications like so:

    private static Logger log;
	
    static {
        ContextSelector selector = StaticLoggerBinder.SINGLETON.getContextSelector();
        LoggerContext ctx = selector.getLoggerContext("myapp");
	log = ctx.getLogger(MyApplication.class);
    }

Replace “myapp” with the context that your class is being used in, like “oflaDemo” for instance. Replace “MyApplication.class” with your class name.

Tags: , , , ,



Reader's Comments

  1. |

    Hi, Thanks for the post, I have been having problems with logging.

    I am just a beginner here.

    My classes are in there=> dream/WEB-INF/classes/com/dream/Application.class . In my source application.java, package name is com.dream . I understand I have to put “dream” in “myapp” like you said, but what shall I put instead of “MyApplication.class” ?
    Also, in the logback config file, what shall I put instead of “my.package.name”, I think it should be “com.dream”.
    Thanks for the help .

  2. |

    Yes, replace MyApplication with Application and you have the package correct (com.dream).

  3. |

    Hi again,

    Where should I exactly put the file “logback-mywebappname.xml”, in my case, “logback-dream.xml”.

    My current code is :
    ContextSelector selector = StaticLoggerBinder.SINGLETON.getContextSelector();
    LoggerContext ctx = selector.getLoggerContext(“dream”);
    log2 = ctx.getLogger(Application.class);
    The first two lines are ok, log2.. is the line giving me error in runtime. My app just stops working at that line. I think it can’t find logback-dream.xml file. Currently, I created that file inside red5/conf folder.

    Thanks for the help.

    Kevin

  4. |

    Hi,

    I have the same problem.
    I get NullPointerException form line:
    LoggerContext ctx = selector.getLoggerContext(“myappname”);

    details:
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
    … 59 common frames omitted
    Caused by: java.lang.NullPointerException
    at pl.touk.fphone.Application.(Application.java:25)
    … 66 common frames omitted

  5. |

    After a long search I found out you need to import these classes to be able to compile this change correctly.

    import ch.qos.logback.classic.LoggerContext;
    import ch.qos.logback.classic.selector.ContextSelector;

  6. |

    However I’m stuck like Tomasz ; Red5 starts and throws an exception at the line:
    LoggerContext ctx = selector.getLoggerContext(“name_of_my_app”);

  7. |

    And I got it to work again after I noticed I had some older jar’s in my WEB-INF/lib/ directory. After removing the jars, Red5 started without errors.

  8. |

    Very confused… followed your instructions and am getting the following error in the log:

    Could not instantiate listener org.red5.logging.ContextLoggingListener
    java.lang.ClassNotFoundException: org.red5.logging.ContextLoggingListener

    In web.xml:

    webAppRootKey
    /eTutor

    org.red5.logging.ContextLoggingListener

    LoggerContextFilter
    org.red5.logging.LoggerContextFilter

    (all references to sfl4 removed)

    in logback-eTutor.xml:

    In .java:
    import org.red5.server.adapter.ApplicationAdapter;
    import org.red5.server.api.IConnection;
    import org.red5.server.api.so.ISharedObject;
    import org.red5.server.api.IScope;
    import org.red5.server.api.IClient;
    import org.slf4j.Logger;
    import org.slf4j.impl.StaticLoggerBinder;
    import ch.qos.logback.classic.LoggerContext;
    import ch.qos.logback.classic.selector.ContextSelector;

    static {
    ContextSelector selector = StaticLoggerBinder.SINGLETON.getContextSelector();
    LoggerContext ctx = selector.getLoggerContext(“eTutor”);
    log = ctx.getLogger(Application.class);
    }

    log4j.properties removed

    I guess my questions come down to:

    1. Does logback-eTutor.xml go in red5/conf or webapps/eTutor/classes/com/milgra?

    2. I don’t know what .jars to remove from the red5/lib directory… do I need to?

    3. Why am I getting the error?

    Noob… if you can’t tell. 😉 Any direction greatly appreciated.

  9. |

    The ContextLoggingListener class is in the red5.jar so I have to assume you are not using a 0.7.1 or 0.8.0 version of Red5.

  10. |

    Hi Paul,
    I tried to use red5 0.8.0 rc1, but after deploying the application I could not access the application. each time I got 404 status message.

    I followed your instruction above, but could not understand what to write in place of my.package.name mentioned in

  11. |

    where does the logback-appname.xml should reside ?

    in webappp/appname/WEB-INF/logback-appname.xml ?

    where does the listener should be added ?

    in webappp/appname/WEB-INF/red5-web.xml ?
    or webappp/appname/WEB-INF/web.xml ?

    using trunk or 0.8.0 … this is so frustrating and confusing

  12. |

    It needs to go on your classpath, which in the case of a web application is in the WEB-INF/classes directory or within a jar in the WEB-INF/lib directory.

  13. |

    Thank you for the infos. I was having big troubles to get those logs in my eclipse console window. I was using the 0.8 RC1 with slf4j logging library and as i switched to the 0.8 RC2 all the problems started to happen. Are you guy’s going to take the RC1 logging feature back because for that new method i need to user an external tool to track my log file in realtime. For the moment it’s the only solution that i finded so i hope that the old eclipse console will revive.

    This is the tool that i’m using to track in realtime my log.

    Trace Log 1.5 : http://tracelog.pbwiki.com/

  14. |

    Hello,
    Thanks for the post.
    I have been having the following problem:

    Context init…
    Logger name for context: red5streamserver
    java.lang.ClassCastException: ch.qos.logback.classic.selector.DefaultContextSelector cannot be cast to org.red5.logging.LoggingContextSelector

    I am using Tomcat 6, Java 6, Ant 1.8.
    I built red5.jar from the source (http://red5.googlecode.com/svn/java/server/tags/0_9), And developed a tomcat project in eclipse where I added the following jars:

    commons-codec-1.4.jar
    commons-httpclient-3.1.jar
    jcl-over-slf4j-1.5.10.jar
    jul-to-slf4j-1.5.10.jar
    log4j-over-slf4j-1.5.10.jar
    logback-classic-0.9.18.jar
    logback-core-0.9.18.jar
    mina-core-2.0.0-RC1.jar
    red5.jar
    red5-remoting.jar
    slf4j-api-1.5.10.jar
    spring-beans-3.0.0.jar
    spring-context-3.0.0.jar
    spring-core-3.0.0.jar
    spring-web-3.0.0.jar

    After making the war (red5streamserver.war) and deploying it into Tomcat I get the error message, I am really stuck with this. I would highly appreciate if you can show me some lights, thank you.

  15. |

    Thx you very much!

  16. |

    Hello

    Any cahnce to get this updated for 0.9.1 and 1.0 versions?

    Thanks
    Cristian



Leave a Comment


Fatal error: Call to undefined function akismet_counter() in C:\xampp\htdocs\paulgregoireblog\wp-content\themes\googlechrome\footer.php on line 9