You can create a custom request cycle which extends the Wicket
WebRequestCycle. This logs the user name in your logs of the user who does
the request.
public class MyRequestCycle extends WebRequestCycle {
private static final Logger logger =
Logger.getLogger(MyRequestCycle.class);
public static final String USER = "USER";
private Time requestStart;
private Time requestEnd;
/**
* Creates a new request cycle.
*
* @param application the application
* @param request the request
* @param response the response
*/
public MyRequestCycle(WebApplication application, WebRequest request,
Response response) {
super(application, request, response);
}
@Override
protected void onBeginRequest() {
requestStart = Time.now();
MDC.put(USER, YourUser.getUsername());
logger.debug("Begin Request");
}
@Override
protected void onEndRequest() {
requestEnd = Time.now();
logger.debug("End Request. Request took " +
TimeFrame.valueOf(requestStart, requestEnd).getDuration());
MDC.remove(USER);
}
@Override
public Page onRuntimeException(Page page, RuntimeException e) {
return null;
}
}
Azzeddine Daddah
www.hbiloo.com
On Mon, Mar 30, 2009 at 4:11 PM, <[email protected]> wrote:
> Hi
>
> I would like to add MDC information(i.e. user login) to my loggs (log4j).
> To do that I have to call MDC.put at the beggining of request
> handling. Im looking for 'interception' functionality in Wicket to add
> MDC code there. Where I should add such code ? RequestCycle ?
>
> Regards
> Daniel
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>