Question

My use case is as following (pseudo code):

def addUser(user) {
  MDC.put(user.id)
  LOG.trace(MyMarkers.ENTRY_POINT, "adding user {}", user);
  calcUser(user)
  MDC.remove(user.id)
}

def calcUser(user) {
  calcUserName(user)
}

def calcUseName(user) {
  storeUserInCache(user)
}

storeUserInCache(user) {
  // is this a good use case? in case I want to enable CACHE feature in TRACE 
  // in logs (for the sake of example or any other feature to enable its tracing 
  // in logs i mark different TRACE with different markers.
  LOG.trace(MyMarkers.CACHE, "storing user {} in cache", user); 
}

getUserFromCache(userid) {
  LOG.trace(MyMarkers.CACHE, "getting user {} from cache", userid)
}

now what i meant by the above is the ability to toggle TRACE on for userid by its MDC and i can also toggle on or off logs for different features. for example by using the CACHE marker I can have my application log all CACHE features in TRACE just because I want to see all caches in trace. is the CACHE marker a good use case for markers? as a toggle to see all CACHE feature in TRACE in my logs?

Was it helpful?

Solution

I believe manipulating logging on a per feature basis is very inline with what markers are made for. It's always good to read up and implement things like that based one existing best practices though.

This question was about best practices for slf4j logback and should be useful: Best practices for using Markers in SLF4J/Logback

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top