You can use the NDC function . Set up a filter / interceptor (depends on what presentation technology you use). Add a nested diagnostic context (filter example):
public class LogDiagnosticContextFilter implements javax.servlet.Filter { @Override public void init(FilterConfig filterConfig) throws ServletException {
Ensure that the filter executed after Spring Security Filter Chain (web.xml):
<filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>logDiagnosticContextFilter</filter-name> <url-pattern>*</url-pattern> </filter-mapping>
Add x to each log4j template of interest:
%x %d %p %t %c - %m%n
Later when you call
LOGGER.info("some text");
anywhere in the code you will see
Username=corresponding_login some text
in your journal
source share