public static void prepareForLogging ( HttpServletRequest request ) { // Add the fishtag for Log4j2 MDC MDC . put ( "timestamp" , System . currentTimeMillis ( ) + "" ) ; MDC . put ( "request_id" , UUID . randomUUID ( ) . toString ( ) ) ; // generate random request id MDC . put ( "request" , request . getRequestURI ( ) ) ; MDC . put ( "ip" , RequestUtils . getClientIpAddress ( request ) ) ; MDC . put ( "user_agent" , RequestUtils . getUserAgent ( request ) ) ; MDC . put ( "method" , request . getMethod ( ) ) ; MDC . put ( "host" , request . getServerName ( ) ) ; MDC . put ( "scheme" , RequestUtils . getScheme ( request ) ) ; MDC . put ( "domain" , UrlUtils . resolveDomain ( request . getServerName ( ) ) ) ; MDC . put ( "port" , request . getServerPort ( ) + "" ) ; MDC . put ( "path" , request . getContextPath ( ) + request . getPathInfo ( ) ) ; if ( request . getUserPrincipal ( ) != null ) { MDC . put ( "user" , request . getUserPrincipal ( ) != null ? request . getUserPrincipal ( ) . getName ( ) : null ) ; } if ( ! StringUtils . isNullOrEmptyTrimmed ( request . getQueryString ( ) ) ) { MDC . put ( "query" , request . getQueryString ( ) ) ; } }
Fills up MDC with request info