<div dir="ltr">The line number solution in log4j is handled like this: <a href="https://logging.apache.org/log4j/2.x/faq.html#logger-wrapper">https://logging.apache.org/log4j/2.x/faq.html#logger-wrapper</a></div><div class="gmail_extra"><br><div class="gmail_quote">On 27 February 2017 at 10:31, Shanholtz, Jeff <span dir="ltr"><<a href="mailto:jeff.shanholtz@intel.com" target="_blank">jeff.shanholtz@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is not a case where I want to inject "global" data into the logs. The guids are very much tied to the context of the code. For instance, all 3 guids might need to be logged at one point, then a method is called in which only the 1st guid is relevant. Once that method returns, it might be back to logging all 3 guids again. And no, I'm not concerned about calls to 3rd party libraries.<br>
<br>
I agree that my wrapper isn't pretty which is the reason I started this topic.<br>
<br>
You ask why is a wrapper better than just plain old logging? It is *marginally* better in that it forces a consistent log message format (important for importing into our ELK stack) and also serves as a reminder to the programmer to include the guids whenever possible.<br>
<br>
Unfortunately Ceki's line number solution doesn't appear to apply. We're using log4j, not logback, and I haven't been able to find a similar log4j solution so far.<br>
<br>
Thanks for the thoughts and ideas, everyone.<br>
<span class="im HOEnZb"><br>
-----Original Message-----<br>
From: slf4j-user [mailto:<a href="mailto:slf4j-user-bounces@qos.ch">slf4j-user-bounces@<wbr>qos.ch</a>] On Behalf Of Joachim Durchholz<br>
Sent: Saturday, February 25, 2017 11:49 PM<br>
To: <a href="mailto:slf4j-user@qos.ch">slf4j-user@qos.ch</a><br>
Subject: Re: [slf4j-user] logging common data simply<br>
<br>
</span><div class="HOEnZb"><div class="h5">On <a href="tel:26.02.2017%2001" value="+12602201701">26.02.2017 01</a>:14, Shanholtz, Jeff wrote:<br>
> Upon investigating MDC, I don’t think it’ll work very well for my<br>
> scenario. I’m not looking for something that is essentially static or<br>
> at least static over some period of time. I’m looking for more of a<br>
> local variable/transient MDC concept.<br>
<br>
MDC is thread-local, with child threads inheriting it from the parent.<br>
I.e. it's sort-of global.<br>
<br>
> In other words, if I were to set MDC<br>
> properties in one method and then call another method, that other<br>
> method may want to log different values for the properties (or none of<br>
> the properties for that matter).<br>
<br>
Maybe you should talk a bit about how your GUIDs go in and out of scope.<br>
Since we don't know about that, we cannot make any useful proposals how to make them available to logging.<br>
<br>
On a tangent, consider the case that some library you are calling is emitting log messages: Do you needs your GUIDs in these messages to find out which of them belong to the same context?<br>
The MDC is the only option to in inject data into such log messages, because 3rd-party library know nothing about your GUIDs, or about your SLF4J wrapper.<br>
<br>
> Unless there’s another way to approach my problem that doesn’t have<br>
> the drawbacks I’m describing, I might be better off sticking with my<br>
> wrapper approach<br>
<br>
The wrapper is a typical code smell, that's why people are trying to find other solutions for you.<br>
Your use case might be the 1% where it's justified anyway. I see vague signs that the wrapper might indeed be a solution, but that it *is* going to make your code inflexible in some ways.<br>
<br>
> GuidLog.guids(xGuid, yGuid, zGuid, logger).info("My log message");<br>
<br>
Where's the advantage over<br>
<br>
<a href="http://logger.info" rel="noreferrer" target="_blank">logger.info</a>("{}/{}/{} My log message", xGuid, yGuid, zGuid)<br>
<br>
?<br>
<br>
If you have lots of debug logging, the wrapper approach will force lots of toString calls and multithreaded hashmap updates inside MDC.put even if the log level does not cover DEBUG, so the wrapper approach would be lower.<br>
<br>
Regards,<br>
Jo<br>
______________________________<wbr>_________________<br>
slf4j-user mailing list<br>
<a href="mailto:slf4j-user@qos.ch">slf4j-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/slf4j-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/<wbr>listinfo/slf4j-user</a><br>
______________________________<wbr>_________________<br>
slf4j-user mailing list<br>
<a href="mailto:slf4j-user@qos.ch">slf4j-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/slf4j-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/<wbr>listinfo/slf4j-user</a></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Matt Sicker <<a href="mailto:boards@gmail.com" target="_blank">boards@gmail.com</a>></div>
</div>