Remote logging for log4js-ext 2.0

The biggest new feature in log4js-ext 2.0 is its support for remote logging to Java web apps.

Providing this feature means that you can perform logging in your ExtJs javascript code, and send it to the server too, where logs will be routed to Log4j, Slf4j or the Apache Commons Logger. All of them are supported.

Configuration: the server side

Steps to add server side support to your Java web app:

  1. Add log4js-ext-remoting-xxx.jar to your Java app -yes, xxx is the library version
  2. 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>
    

That’s it!

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…

3 responses to “Remote logging for log4js-ext 2.0

  1. Pingback: Log4js-ext 2.0 is out! | Software Development "Built to Last"

  2. Dilip Ramji

    Hi,

    Is log4js-ext-remoting-2.0.jar available as a maven dependency?

    Thanks,

    Dilip

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s