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 Respuestas a “Remote logging for log4js-ext 2.0

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

  2. Hi,

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

    Thanks,

    Dilip

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s