1

I have a spring boot application using logback for logging and it is working normally. I have a change to implement which is to log a value on runtime in every error - warn log record. For example I want to append the request param to every log:

"User ID {} ", request.getHeader("userId") + // here comes the normal log.

I am planning to user:

@Autowired
private HttpServletRequest request;

To be able to catch the needed data. But how can I append this value to all error logs without adding toomuch code ( like using AOP or extended common class etc)

Lutzi
  • 416
  • 2
  • 13
user666
  • 1,750
  • 3
  • 18
  • 34
  • Does this answer your question? [Spring Boot - How to log all requests and responses with exceptions in single place?](https://stackoverflow.com/questions/33744875/spring-boot-how-to-log-all-requests-and-responses-with-exceptions-in-single-pl) – jannis Jan 29 '20 at 08:46
  • What I want is more like a wrapper or decorator on top of the logging I use in my code – user666 Jan 29 '20 at 13:02
  • 1
    It'll be error-prone, cumersome and pretty much pointless to wrap the logging framework. The only other sensible option apart from AOP is MDC. Something like here: [How to use MDC of logback and SLF4J with spring boot to capture unique tracking in the POST request json?](https://stackoverflow.com/questions/46563316/how-to-use-mdc-of-logback-and-slf4j-with-spring-boot-to-capture-unique-tracking) – jannis Jan 29 '20 at 15:04

0 Answers0