Reputation: 41
My light-4j application is using AuditHandler to print access logs. The default format printed is:
{"timestamp":1580470146236,"endpoint":"/mmt/register@post","X-Correlation-Id":"123456","statusCode":200,"responseTime":70}
But, the client is hitting the API with query parameters: /mmt/register?id=2
How do I customize the access log so that it prints the query parameter also in the access log? {"timestamp":1580470146236,"endpoint":"/mmt/register@post?id=2","X-Correlation-Id":"123456","statusCode":200,"responseTime":70}
My current logback setting is:
<appender name="access-log" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>/opt/logs/Register/access.json</File>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/opt/logs/Register/access.%d{yyyy-MM-dd}.%i.json
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 1GB -->
<maxFileSize>1GB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<MaxHistory>50</MaxHistory>
</rollingPolicy>
<encoder>
<Pattern>%m%n</Pattern>
</encoder>
</appender>
Upvotes: 0
Views: 114
Reputation: 388
The default AuditHandler only logs endpoint that is the path and method combination. The query parameter is not part of it. To log the query parameters, there are two options.
Customize the AuditHandler in the light-4j repo and replace it with the customized on in the handler.yml file if you want to log the query parameter in production.
If you just need to log the query parameter in the dev environment, then you can wire in the DumpHandler. It basically dumps everything on request and response including headers, query parameters, path parameters, cookies, and the request body. However, it slows down the system dramatically and it is not recommended to enable it in production. Take a look at the handler.yml file to uncomment the handler and uncomment the alias in the default chain.
Upvotes: 0