RE: wicket & log4j MDC
You can extend WicketFilter like this public class ImpactServletFilter extends WicketFilter { @Override public void init(FilterConfig filterConfig) throws ServletException { super.init(filterConfig); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { super.doFilter(request, response, chain); } finally { // put is done in onBeginRequest where I have the ApplicationSession of wicket with my user MDCHelper.get().remove(MDCHelper.ID); } } @Override public void destroy() { super.destroy(); } } Don't forget to change also your web.xml : ImpactApplication com.tsquare.impact.util.ImpactServletFilter applicationClassName com.tsquare.impact.ImpactApplication ImpactApplication /* REQUEST ERROR Regards, Fabrice m00kie wrote: > > Hi, > > I would like to add some MDC information to logs of wicket RequestLogger. > Unfortunatelly these MDC information are missed as RequestLogger invokes > it's logging after invocation of WebRequestCycle.onEndRequest method which > removes MDC entires. > > Is it a workaround for doing that? > -- View this message in context: http://www.nabble.com/wicket---log4j-MDC-tp22784121p25818319.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
RE: wicket & log4j MDC
Hi, I would like to add some MDC information to logs of wicket RequestLogger. Unfortunatelly these MDC information are missed as RequestLogger invokes it's logging after invocation of WebRequestCycle.onEndRequest method which removes MDC entires. Is it a workaround for doing that? -- View this message in context: http://www.nabble.com/wicket---log4j-MDC-tp22784121p24110412.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
RE: wicket & log4j MDC
Yes. In your application, override newRequestCycle and return a custom rc that uses onBeginRequest (IIRC) to do this. Jeremy Thomerson http://www.wickettraining.com -- sent from a wireless device -Original Message- From: daniel.lipski...@gmail.com Sent: Monday, March 30, 2009 9:11 AM To: users@wicket.apache.org Subject: wicket & log4j MDC 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: wicket & log4j MDC
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, 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: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >