In my spring boot microservice module I would like to capture specific request header values from a http servlet request through tomcat access log and use the header value in my logback logging.
I am using logback xml only, no logback-access file. My requirement is to accomplish this through configuration without a programmatic solution. I configured my YAML in the "env" section to get the tomcat access log. For this I have configured my spring boot application "env" section of YAML to append tomcat access log to the application log as follows:
env:
server.tomcat.accesslog.enabled: true
server.tomcat.accesslog.directory: "/dev"
server.tomcat.accesslog.prefix: stdout
server.tomcat.accesslog.buffered: false
server.tomcat.accesslog.suffix:
server.tomcat.accesslog.file-date-format:
server.tomcat.accesslog.pattern: "[ACCESS] %l %t %D %F %B %S X-myHeader=%{X-myHeader}i"
I also added a logger in my logback to print the tomcat access logging. With this change my incoming Request header value is printing to the spring boot logs as a separate line for each request. Instead i would like to access this header value as a property in the logback xml and log it along with the application properties, all in a single line in the logs.
Is there a way to access the "server.tomcat.accesslog.pattern" as a property and make its value available in the logback xml, I am just thinking. For example in the logback xml, I tried to declare a property like this: I tried this but the spring boot log states "X-myHeader" is undefined.
Has anyone tried this successfully, I would like to know what i am missing here. My requirement is to accomplish this through configuration without a programmatic solution.