Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Logging custom attributes in log4j.

Alessandro Izzo
9 years ago Oct 25, 2013 8:16pm
Henri Sara
9 years ago Oct 28, 2013 9:28am
Alessandro Izzo
9 years ago Oct 30, 2013 11:41am

Thanks, Henry

Following your advice, and reading thread 3214685, I could solve my problem extending VaadinServlet.

My code:

    public static class Servlet extends VaadinServlet
    {
        @Override
        protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException
        {
            VaadinServletService servletService = new VaadinServletService(this, deploymentConfiguration)
            {           
                
                @Override
                public void requestStart(VaadinRequest request, VaadinResponse response)
                {
                    super.requestStart(request, response);
                    MDC.put("address", request.getRemoteAddr());
                }

                @Override
                public void requestEnd(VaadinRequest request, VaadinResponse response, VaadinSession session)
                {
                    super.requestEnd(request, response, session);
                    MDC.remove("address");
                }
            };
            servletService.init();
            return servletService;
        }
    }