How to avoid duplicate logs in stateless call

Viewed 44

In our application same client can call same request multiple time , we do this logging for each request

We want to avoid such logging and want to log only when there is some change in user call

So for example within 600 sec, if same user is doing call with same parameters multiple time then only one message should be log

Is there any generic solution for this Using log4j at our end in Java application for logging

1 Answers

I don't recommend such an approach. Skipping some logs on purpose distorts the reality and might cause problems in the future. Such behavior is also not transparent and would lead to misinterpretation of the log.

Consider caching:

...if same user is doing call with same parameters multiple time...

This sentence immediately triggers an idea of caching. You might want to cache such a response and log the fact it has been obtained from the cache instead: you can also decrease the log level from INFO to DEBUG only upon your consideration.

Related