include header value and sessionid in logback

This feature is available since v9.5.3

In this example we'll add a custom header and the current sessionid to the logback pattern.

For starters we'll add the header into the Nginx configuration. In this case we're crafting a unique request id for each incomming request. This might be useful to extract the logs of one single request.


Add this line to the nginx config:

proxy_set_header              X-Request-Id $request_id;

Change the IDHub context to add that header to the logged headers

<Environment name="LOG_HEADERS" value="X-Request-Id,Host,X-Some-Other-Header-I-Want-To-Log" type="java.lang.String" override="false"/>

Change the logback configuration to log the session ID and the request header (or the host header, or both). All the headers can be accessed via the pattern %X{H_CASESENSITIVEHEADERNAME}

<Pattern>[%d{dd-MM-yyyy HH:mm:ss.SSS}] [%X{H_X-Request-Id}] [%X{JSESSIONID}] [%thread] %-5level %logger{36} - %msg %n</Pattern>

After restarting the gateway and Tomcat, the new settings are applied.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.