<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">No, it sounds like what you’re describing isn’t what I’m seeking. I’m talking purely about logging. The comment about multiple microservices was tangential. We’re
 using kafka for communicating between the microservices. Thanks for the thought though!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Upon investigating MDC, I don’t think it’ll work very well for my scenario. I’m not looking for something that is essentially static or at least static over some
 period of time. I’m looking for more of a local variable/transient MDC concept. In other words, if I were to set MDC properties in one method and then call another method, that other method may want to log different values for the properties (or none of the
 properties for that matter).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Could I make it work somehow? Probably. I just messed around with one idea I had. It would definitely require a standardized approach to logging and avoiding
 use of loggers without doing some MDC interaction or else log messages which <i>
shouldn’t</i> have one or more of the guids will get them anyway.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Unless there’s another way to approach my problem that doesn’t have the drawbacks I’m describing, I might be better off sticking with my wrapper approach and
 trying Ceki’s solution for line numbers.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">FWIW here’s the attempt I made at using MDC for my purpose but then I realized the potential for problems if someone uses a logger without this:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:white;text-autospace:none"><b><span style="font-size:9.0pt;font-family:"Courier New";color:navy">public class
</span></b><span style="font-size:9.0pt;font-family:"Courier New";color:black">GuidLog {<br>
    </span><b><span style="font-size:9.0pt;font-family:"Courier New";color:navy">public static
</span></b><span style="font-size:9.0pt;font-family:"Courier New";color:black">Log guids(Object xGuid, Object yGuid, String zGuid, Log log) {<br>
        MDC.<i>put</i>(</span><b><span style="font-size:9.0pt;font-family:"Courier New";color:green">"xGuid"</span></b><span style="font-size:9.0pt;font-family:"Courier New";color:black">, xGuid.toString());<br>
        MDC.<i>put</i>(</span><b><span style="font-size:9.0pt;font-family:"Courier New";color:green">"yGuid"</span></b><span style="font-size:9.0pt;font-family:"Courier New";color:black">, yGuid.toString());<br>
        MDC.<i>put</i>(</span><b><span style="font-size:9.0pt;font-family:"Courier New";color:green">"zGuid"</span></b><span style="font-size:9.0pt;font-family:"Courier New";color:black">, zGuid.toString());<br>
        </span><b><span style="font-size:9.0pt;font-family:"Courier New";color:navy">return
</span></b><span style="font-size:9.0pt;font-family:"Courier New";color:black">log;<br>
    }<br>
}<br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal" style="background:white;text-autospace:none"><span style="font-size:9.0pt;font-family:"Courier New";color:black;background:#E4E4FF">GuidLog</span><span style="font-size:9.0pt;font-family:"Courier New"">.<i>guids</i>(xGuid, yGuid, zGuid,
<b><i><span style="color:#660E7A">logger</span></i></b><span style="color:black">).info(</span><b><span style="color:green">"My log message"</span></b><span style="color:black">);<br>
<br>
<o:p></o:p></span></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> slf4j-user [mailto:slf4j-user-bounces@qos.ch]
<b>On Behalf Of </b>Matt Sicker<br>
<b>Sent:</b> Saturday, February 25, 2017 1:55 PM<br>
<b>To:</b> User list for the slf4j project <slf4j-user@qos.ch><br>
<b>Subject:</b> Re: [slf4j-user] logging common data simply<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Generally, what you're describing isn't necessarily the MDC. It sounds more like distributed tracing:<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="http://opentracing.io/">http://opentracing.io/</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="http://zipkin.io/">http://zipkin.io/</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The MDC/ThreadContext APIs are useful for maintaining contextual data within threads, but if you want to propagate between microservices or do any sort of correlation, you'll need to standardize ways on passing that context data over HTTP,
 JMS, etc. A couple projects exist out there that can instrument your IPC with the relevant ids and will send log messages to a Zipkin collector (or similar):<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="https://github.com/openzipkin/brave">https://github.com/openzipkin/brave</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="https://cloud.spring.io/spring-cloud-sleuth/">https://cloud.spring.io/spring-cloud-sleuth/</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">If this is what you're working on, then I hope this helps! I'm working on a very similar project at my work right now, so this is all fresh.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 25 February 2017 at 14:40, Shanholtz, Jeff <<a href="mailto:jeff.shanholtz@intel.com" target="_blank">jeff.shanholtz@intel.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal">Thanks for the quick responses everyone! Now I know what to start researching. :)<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
-----Original Message-----<br>
From: slf4j-user [mailto:<a href="mailto:slf4j-user-bounces@qos.ch">slf4j-user-bounces@qos.ch</a>] On Behalf Of Ceki Gülcü<br>
Sent: Saturday, February 25, 2017 12:37 PM<br>
To: User list for the slf4j project <<a href="mailto:slf4j-user@qos.ch">slf4j-user@qos.ch</a>><br>
Subject: Re: [slf4j-user] logging common data simply<br>
<br>
<br>
Regarding wrong line numbers shown with your log wrapper, with logback you can fix the issue by calling:<br>
<br>
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();<br>
lc.getFrameworkPackages().add("package of log wrapper");<br>
<br>
Best regards,<br>
<br>
--<br>
Ceki<br>
<br>
On 2/25/2017 21:15, Joachim Durchholz wrote:<br>
> On <a href="tel:25.02.2017%2020">25.02.2017 20</a>:34, Shanholtz, Jeff wrote:<br>
>> I have a scenario where I have 1, 2, or 3 pieces of data (guids)<br>
>> which I want to to log with all messages in order to track records as<br>
>> they traverse their way through a series of microservices.<br>
><br>
> That's a common scenario.<br>
><br>
>> Currently I’ve written my own wrapper class with my own debug, info,<br>
>> warn, error methods that take these 3 parameters, followed by the<br>
>> message field, followed by the optional parameters.<br>
><br>
> Any library function that you call will still use the original loggers<br>
> so you won't know with which of the guids some log message from deep<br>
> inside a call is associated.<br>
> This is a real PITA if you have multiple requests executing in parallel.<br>
><br>
>> There must be a better way, plus this has the disadvantage of<br>
>> rendering the line number useless in log messages because the line<br>
>> numbers are the line numbers from my log wrapper class, not the<br>
>> actual code doing the logging.<br>
><br>
> Elliot has the start of the trail right: Use an MDC.<br>
> The other half of the trail is that formatters have an escape code for<br>
> extracting data from the MDC (%m if I remember correctly).<br>
><br>
> HTH<br>
> Jo<br>
_______________________________________________<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" target="_blank">http://mailman.qos.ch/mailman/listinfo/slf4j-user</a><br>
_______________________________________________<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" target="_blank">http://mailman.qos.ch/mailman/listinfo/slf4j-user</a><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">-- <o:p></o:p></p>
<div>
<p class="MsoNormal">Matt Sicker <<a href="mailto:boards@gmail.com" target="_blank">boards@gmail.com</a>><o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>