Wicket’s RequestLogger

Wicket provides you with a build-in request logger. It can give you a lot of information. See also example below. To activate this logger you have to enable the logger and setup (in our case) some Log4j configuration. In this post I’ll show you how to get this done.


The example below shows you how to enable the requestLogger when the application is started in “Development” mode.

//Check if we are not in deployment mode.
if (!DEPLOYMENT.equalsIgnoreCase(getConfigurationType())) {
  
  //Get the logger
  IRequestLoggerSettings reqLogger = Application.get().getRequestLoggerSettings();
  
  //Enable the logger
  reqLogger.setRequestLoggerEnabled(true);

  /**
  * Set the window of all the requests that is kept in memory for viewing. Default is 2000, You
  * can set this to 0 then only Sessions data is recorded (number of request, total time, latest
  * size)
  */
  reqLogger.setRequestsWindowSize(3000);
}

If you want to log everything to a specific rolling file you can add the following lines to your log4j.properties file. It will create a file for you with a max. size of 10MB. All Wicket requests will be logged into this file and not in the ‘general’ log.

log4j.category.org.apache.wicket.protocol.http.RequestLogger = info,reqLogger
log4j.additivity.org.apache.wicket.protocol.http.RequestLogger=false
log4j.appender.reqLogger=org.apache.log4j.RollingFileAppender
log4j.appender.reqLogger.File=D:/logs/wicketRequestLogger.txt
log4j.appender.reqLogger.MaxFileSize=10MB
log4j.appender.reqLogger.MaxBackupIndex=10
log4j.appender.reqLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.reqLogger.layout.ConversionPattern=%d %-5p - %-26.26c{1} - %m\n

Example logging:
2009-04-08 16:18:32,878 INFO – RequestLogger-
time=687,
event=Interface[target:Login$LoginForm(bodyTag:loginForm),
page: eu.company.desktop.wicket.ui.login.Login(0),
interface: IFormSubmitListener.onFormSubmitted],
response=org.apache.wicket.request.target.basic.RedirectRequestTarget@1c82b58,
sessionid=C488C8A534D1D853FD1F7A80C5647A52.jvm1,
sessionsize=16239,
sessionstart=Wed Apr 08 14:18:23 GMT 2009,
requests=12,
totaltime=3499,
activerequests=1,
maxmem=532M,
total=163M,
used=93M

That’s it.

Disclaimer: The requestLogger is very powerfull. I just started experimenting with it, so I don’t know all ins and outs yet. 😉

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>