-1

This question is around logging. I need to implement a custom log utils which will be used across multiple services and . this should be capable of logging few attributes (the service name, endpoint uri accessed, etc) in a log event by default without the utility user need to specifying these.

Eg. user might say

mylogutil.debug("order has been placed")

however, the output should be...

DEBUG|service-one|/api/orders|usweridone|oder_id-1| order has been placed

the reason behind this is except the log message other attributes can be extracted from the incoming request by a filter, from a properties file or an env variable etc.. and every logger statement entry doesn't have to contain this.

Please help me with a fair way to do this.

crs
  • 91
  • 1
  • 1
  • 6

2 Answers2

0

It looks like Thread Context may meet your needs. It is also supported via the SLF4J API. Be careful though, as it is known to have issues with thread pools.

I would also suggest you to review Using Log4j 2 in Web Applications.

Community
  • 1
  • 1
vempo
  • 3,093
  • 1
  • 14
  • 16
  • Thanks vempo, I found MDC readily available in slf4j/log4j2 and I have implemented it to populate the require common log attributes in servlet filters and other interceptors as applicable. http://www.slf4j.org/manual.html – crs Sep 08 '16 at 15:25
0

I found MDC readily available in slf4j/log4j2 and I have implemented it to populate the require common log attributes in servlet filters and other interceptors as applicable. Please see http://www.slf4j.org/manual.html for MDC

crs
  • 91
  • 1
  • 1
  • 6