The biggest new feature in log4js-ext 2.0 is its support for remote logging to Java web apps.
Configuration: the server side
Steps to add server side support to your Java web app:
- Add log4js-ext-remoting-xxx.jar to your Java app -yes, xxx is the library version
- Configure the remote logging servlet, as follows:
<servlet> <servlet-name>Log4jsExtServlet</servlet-name> <servlet-class>com.softwarementors.log4jsext.remote.Log4jsExtServlet </servlet-class> <servlet-mapping> <servlet-name>Log4jsExtServlet</servlet-name> <url-pattern>/remotelogrequest</url-pattern> </servlet-mapping> </servlet>
Of course, you will have to provide the logging jars for Log4j, Slf4j or the Apache Commons Logger -but you already knew that!
Configuration: the client side
You can keep your current logs as they are, there is no need to modify your logging code in the client side. That transparency is one of the reason why you are using log4js-ext for your logging needs.
All you need to do is register one or more of the new appenders: they know how to send log data to your remote application.
Here is source code that registers appenders for Log4js, Slf4j and Apache Commons Logger with the root logger: this causes all client side logs to go to the remote web app by default.
// Configure simple remote logging Sm.log.Logger.getRoot().addAppender( Sm.log.remote.RemoteAppender.createLog4jAppender( "/log4js-ext/remotelogrequest") ); Sm.log.Logger.getRoot().addAppender( Sm.log.remote.RemoteAppender.createSlf4jAppender( "/log4js-ext/remotelogrequest") ); Sm.log.Logger.getRoot().addAppender( Sm.log.remote.RemoteAppender.createApacheCommonsLoggingAppender( "/log4js-ext/remotelogrequest") );
Now, if this has not convinced you of the power of log4js-ext, I don’t know what will do…