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:

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:

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:

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

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"?>
<appender name="myAppenderNameHere" class="ch.qos.logback.core.FileAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
%date [%thread] %-5level %logger{35} - %msg%n
<level value="DEBUG" />
<appender-ref ref="myAppenderNameHere" />
<logger name="com.company.webAppName">
<level value="DEBUG" />

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: