I could be wrong, but I think you are looking for MDC. https://www.slf4j.org/manual.html
See the section titled "Mapped Diagnostic Context (MDC) support" On Sat, Feb 25, 2017 at 12:34 PM, Shanholtz, Jeff <[email protected]> wrote: > I have a scenario where I have 1, 2, or 3 pieces of data (guids) which I > want to to log with all messages in order to track records as they traverse > their way through a series of microservices. > > > > Currently I’ve written my own wrapper class with my own debug, info, warn, > error methods that take these 3 parameters, followed by the message field, > followed by the optional parameters. > > > > There must be a better way, plus this has the disadvantage of rendering > the line number useless in log messages because the line numbers are the > line numbers from my log wrapper class, not the actual code doing the > logging. > > > > What is the best way to handle this scenario? Googling has failed me, as > has the FAQ, but it’s probably because I don’t know the right terms to > search for. I’m using log4j2 as the underlying logger FWIW. > > > > Here’s a simplified version of my log wrapper (i.e. most methods stripped > out because they are redundant for the purpose of this question): > > > > *public class *Log { > *private *Logger *logger*; > > *public *Log(Class clazz) { > *logger *= LoggerFactory.*getLogger*(clazz); > } > > *public void *info(Object xGuid, Object yGuid, String zGuid, String > message, Object... args) { > *logger*.info(guidifiedMessage(xGuid, yGuid, zGuid, message), > args); > } > } > > > > The “guidifiedMessage” method just prefixes the message string with > whatever guids are present. > > > > So is there a better way? Or if not, is there at least a way to get the > line number specified in my log4j properties to reflect the caller of this > Log class rather than the line *within *the Log class? > > _______________________________________________ > slf4j-user mailing list > [email protected] > http://mailman.qos.ch/mailman/listinfo/slf4j-user >
_______________________________________________ slf4j-user mailing list [email protected] http://mailman.qos.ch/mailman/listinfo/slf4j-user
