Tuesday, October 20, 2009

Red5 0.7.0 Logging Success!!

Well, for the first time today, I got the Red5 logback logger to work.

The revelation hit me when I realized after reading:
http://www.avchat.net/blog/missing-red5-log-files-where-are-they/

That the log directory is expected in a different location depending on whether you use the red5.bat, or the Windows Service to launch the red5 server.

The demo applications which write to a log have logback.xml in the folder:
[appNameHere]/WEB-INF/classes/logback.xml

i) With the red5.bat launching method, all of the demo webapps merrily log to their logs using the XML reference to the log directory of:
<File>log/aaecWebinar.log</File>

ii) With the Windows service launching method, the demo apps all stop logging... unless you change the XML reference to the log directory of:
<File>../log/aaecWebinar.log</File>



logback.xml Red5 Notes:


i) Change all the "myAppenderNameHere" references to be the same string (your choice)
ii) Change "com.company.webAppName" to the package name of your red5 java application.


<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="myAppenderNameHere" class="ch.qos.logback.core.FileAppender">
<File>../log/aaecWebinar.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>
<level value="DEBUG" />
<appender-ref ref="myAppenderNameHere" />
</root>
<logger name="com.company.webAppName">
<level value="DEBUG" />
</logger>
</configuration>



Java code:



i) The following 2 imports are required:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

ii) And in my constructor, I configure the Logger:

public class Application extends ApplicationAdapter {
protected static Logger log = LoggerFactory.getLogger(Application.class);
[..... other code follows .... ]

iii) And then I call the logger methods.

public boolean appConnect( IConnection conn , Object[] params ){
log.info("appConnect id: " + conn.getClient().getId() );
}


Hopefully this clears things up. Let me know how things go!

No comments: