Olle thanks,
this is what I did:
public class RequestLoggingFilter implements HttpServletRequestFilter {
public final RequestGlobals requestGlobals;
public RequestLoggingFilter(final RequestGlobals requestGlobalss) {
this.requestGlobals = requestGlobalss;
}
@Override
public boolean service(HttpServletRequest request, HttpServletResponse
response, HttpServletRequestHandler handler)
throws IOException {
MDC.put("remoteIP",
this.requestGlobals.getHTTPServletRequest().getRemoteAddr());
String s =
this.requestGlobals.getHTTPServletRequest().getRequestedSessionId();
if (s == null) {
s = "";
}
MDC.put("sessionID", s);
return handler.service(request, response);
}
}
and in my AppModule.java
public RequestLoggingFilter buildRequestLoggingFilter(final
RequestGlobals requestGlobals) {
return new RequestLoggingFilter(requestGlobals);
}
public static void contributeHttpServletRequestHandler(
OrderedConfiguration<HttpServletRequestFilter> configuration,
@InjectService("RequestLoggingFilter") HttpServletRequestFilter
myfilter) {
configuration.add("myfilter", myfilter, "before:*");
}
but I feel I am missing something. Where do I put the code:
MDC.remove("remoteIP");
MDC.remove("sessionID");
Thanks,
Borut
2009/10/9 Olle Hallin <[email protected]>
> We do something similar. We have implemented a RequestFilter that pushes
> the
> HttpSession ID (if any) onto the Log4j Nested Diagnostics Context (NDC)
> before the request, and pops it afterwards.
> I guess that the same approach could be used for pushing usernames in the
> SLF4J MDC, provided that you can get hold of them from a RequestFilter.
>
> Good to know: Tapestry 5.1 stores @SessionStateObjects in the session under
> the key "sso:" + MySessionStateObject.class.getName(). ("aso:" in 5.0.*)
>
> HTH,
> Olle
>
> Senior Java Developer and Architect
> [email protected]
> www.crisp.se
>
>
>
>
> 2009/10/9 Borut Bolčina <[email protected]>
>
> > Hello,
> >
> > has anybody implemented logging with MDC %X{username}?
> >
> > I would like to track users in my logs by their username and/or IP
> address.
> > Before I dive in, I just wanna ask if someone has already done it?
> >
> > Thanks, Borut
> >
>