Reputation: 1101
I have some ids (id from database, example 34645) that I currently log as "[34645] - something happended" using something like:
log.info("[" + id + "]" + foo);
Some logs, like "server starting", "database connection bla" dont have an id and thus doesn't log any and that's fine.
However, when I have an id I call methods that also log, but don't have the id, like:
lookup(name) {
//do some lookup and stuff
log.info("[" + name + "]" has some info we use somewhere: " + result);
}
Is there a (smart) way to get the id logged inside lookup() without passing id to lookup() or refactor class hierarchies? There are different threads logging so setting/unsetting id-values for logback to use will probably be difficult to get right.
Upvotes: 0
Views: 41
Reputation: 6456
as per request and I like credits, you can use MDC for that thing.
Info on that is here: http://logback.qos.ch/manual/mdc.html
Thanks :)
Upvotes: 1