The behavior of the ServletContext.log method is container specific. The method I used to make it sequential is to wrap a ServletConfig passed through init () to create a wrapped ServletContext that uses our own provided logger (Slf4j in this case).
public class Slf4jServletConfigWrapper implements ServletConfig { private final ServletConfig config; private final Logger log; public Slf4jServletConfigWrapper(Logger log, ServletConfig config) { this.log = log; this.config = config; } public ServletContext getServletContext() { return new ServletContext() { public void log(String message, Throwable throwable) { log.info(message, throwable); } public void log(Exception exception, String msg) { log.info(msg, exception); } public void log(String msg) { log.info(msg); } ...
Full code Slf4jServletConfigWrapper.java
In your Servlet, override the init () method to use the ServletConfig wrapper
public void init(final ServletConfig config) throws ServletException { super.init(new Slf4jServletConfigWrapper(log, config)); }
source share