But if you want to output http header values with any business log message from the application, you would need to use the so-called MDC feature: http://logback.qos.ch/manual/mdc.html
So you create an HTTP filter in a core and/or web module. This filter intercepts all requests and sets up MDC logging context:
public class RequestHeaderFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
MDC.put("remoteAddr", request.getRemoteAddr());
try {
chain.doFilter(request, response);
} finally {
MDC.remove("remoteAddr");
}
}
@Override
public void destroy() {
}
}