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.
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.
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: context, log, logger, Red5, web.xml
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 .
View this Comment in:

Yes, replace MyApplication with Application and you have the package correct (com.dream).
View this Comment in:

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
View this Comment in:

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
View this Comment in:

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;
View this Comment in:

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

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.
View this Comment in:

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.
View this Comment in:

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.
View this Comment in:

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
View this Comment in:
