I am logging Thread Context values in application logs successfully with %X pattern. Now, I want to log the same value in Tomcat access logs.
Is there any pattern for that?
You can't log thread context in access log, I'm afraid.
Here's available options:
%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or '-' if zero
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method (GET, POST, etc.)
%p - Local port on which this request was received. See also %{xxx}p below.
%q - Query string (prepended with a '?' if it exists)
%r - First line of the request (method and request URI)
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format
%u - Remote user that was authenticated (if any), else '-'
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis
%T - Time taken to process the request, in seconds
%F - Time taken to commit the response, in millis
%I - Current request thread name (can compare later with stacktraces)
As far as I know, the only thing you can do is to log the current thread name (%I) and then look it up in the application logs in order get its context information.
I had a similar requirement where I have to log correlation Id in my access logs which was set in MDC. I could not find a way to write MDC to access logs, but in my cases since I was writing the correlationId from MDC to outbound request headers, I leverage this to copy the value from headers into access logs.
Ex
server.tomcat.accesslog.pattern=%A %t %m %U %q %H %s %D %{X-Correlation-Id}o
X-Correlation-Id was my header name and o in the end says to read the value from outbound request.
This helped me out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With