Ajax Message Queue with Log4j

Ajax Message Queue with Log4j

Ajax Message Queue is enable to poll messages logged with log4j on server side.

To use Ajax Message Queue with log4j, you must :

You can use Ajax Message Queue with log4javascript to log messages into Browser Console (works with FireFox or Opera). See distribution to show the example.

AjaxAppender

AjaxAppender is an appender which get queue with MessageQueueRepository for the log4j context and specific scope (defined into log.properties) and add Log4JMessage to the queue. Log4JMessage implements IJSONMessage which contains LoggingEvent, and Layout.

To manage an AjaxAppender, you must define an AJAX appender in your log4j.properties like this :

  log4j.appender.My_AJAX_APPENDER=net.sourceforge.jscontrolstags.messagequeue.log4j.AjaxAppender

To set a scope for your AjaxAppender, use scope property, like this :

  # scope=application, session or request
  log4j.appender.My_AJAX_APPENDER.scope=application  

Here an example of log4j configuration to poll messages of log4j (context) with application scope.

  
  # AjaxAppender for application scope
  log4j.appender.AJAX-APPLICATION-SCOPE=net.sourceforge.jscontrolstags.messagequeue.log4j.AjaxAppender
  log4j.appender.AJAX-APPLICATION-SCOPE.scope=application
  log4j.appender.AJAX-APPLICATION-SCOPE.layout=org.apache.log4j.PatternLayout
  log4j.appender.AJAX-APPLICATION-SCOPE.layout.ConversionPattern=- %m%n%d{dd MMM yyyy HH:mm:ss,SSS} %-4r [%t] %-5p %c %x - %m%n

  # register AjaxAppender
  log4j.logger.net.sourceforge.jscontrolstags.usecases=DEBUG, AJAX-APPLICATION-SCOPE
  

Advanced configuration

If you want configure (with message-config.xml several queues whith log4j which have different behaviours like clear queue on each request (or not), initialize lazyless queue (or not), you can set a context for the AjaxAppender, like this :

  
  # By default context is log4j
  log4j.appender.MY_AJAXAPPENDER_WITH_CUSTOM_CONTEXT.context=custom_context
  

jscontrols-ajax:messageQueue

To poll messages of log4j with application scope, you must define jscontrols-ajax:messageQueue like this :

  <!-- Include javascript required -->                    
  ...
  
  <jscontrols-ajax:messageQueue 
          ...
          context="log4j"
          scope="application"
          ... />