I like the idea of making it obvious when there is no value for an existing field (i.e. "null") and when there is no way to get to the field (e.g. "???0.number???"). I'll have to look into making that happen.<div>
(*Chris*)<br><br><div class="gmail_quote">On Mon, Feb 13, 2012 at 11:09 AM, Tony Trinh <span dir="ltr"><<a href="mailto:tony19@gmail.com">tony19@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That seems reasonable to me, but instead of "null" (which could be a legitimate value), how about an error string that stands out? I suppose the refactoring inconvenience is minor after all, and the advantages perhaps outweigh it, especially with your suggested warning print-out.<span class="HOEnZb"><font color="#888888"><div>
<br></div><div>-Tony</div></font></span><div class="HOEnZb"><div class="h5"><div><br></div><div><div class="gmail_quote">
On Mon, Feb 13, 2012 at 1:10 PM, Chris Pratt <span dir="ltr"><<a href="mailto:thechrispratt@gmail.com" target="_blank">thechrispratt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That's a good point, right now it would eat the exception (logging should never interfere with the operation of a possibly production system) and just log a "null" for that value, which isn't as helpful as it could be. Maybe I could have it log "missing value:0.number" or something like that.<div>
<span><font color="#888888">
(*Chris*)</font></span><div><div><br><br><div class="gmail_quote">On Mon, Feb 13, 2012 at 9:44 AM, Tony Trinh <span dir="ltr"><<a href="mailto:tony19@gmail.com" target="_blank">tony19@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Actually, I meant the refactoring of a class that was being used by a "new & improved" formatted string. If, for example, I had this formatted string:<div><br><br><span style="font-family:'courier new',monospace">log.</span><font color="#00007f" style="font-family:'courier new',monospace">debug</font><span style="font-family:'courier new',monospace">(</span><font color="#007f00" style="font-family:'courier new',monospace">"Loading Student [{0.number}] {<a href="http://0.name/" target="_blank">0.name</a>} Enrolled: {0.enrollmentDate,date,yyyy-MM-dd}"</font><span style="font-family:'courier new',monospace">,student);</span> <br>
<br></div>and down the road, someone decides to remove the <font face="'courier new', monospace">number </font>field from the <font face="'courier new', monospace">Student </font>class without realizing it was in use here, the code would compile just fine, but the effect (presumably an exception) would not be noticed until this log statement was executed.<div>
<div><div>
<br></div><div><br><div class="gmail_quote">On Mon, Feb 13, 2012 at 12:35 PM, Chris Pratt <span dir="ltr"><<a href="mailto:thechrispratt@gmail.com" target="_blank">thechrispratt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Well, not exactly. It works just fine with the Log4j/java.util.logging style logging, but it would require refactoring any SLF4j {} based mappings. Then again, if it was added as an additional option rather than a replacement, that problem would go away as well. If you could continue to get the Logger instances from the LoggerFactory, or a new Log instance that used my format, you could slowly transition to the "new & improved" without requiring a wholesale change.<div>
<span><font color="#888888">
(*Chris*)<br><br></font></span><div class="gmail_quote"><div><div>On Mon, Feb 13, 2012 at 9:24 AM, Tony Trinh <span dir="ltr"><<a href="mailto:tony19@gmail.com" target="_blank">tony19@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
I'm a fan of this idea (if you couldn't already tell). A couple disadvantages that come to mind is lack of syntax-checking in the string and painful refactoring (it requires the programmer to search every formatted string for correctness). In any case, what would be the appropriate action for syntax errors that are discovered at runtime?<span><font color="#888888"><div>
<br></div><div>-Tony</div></font></span><div><div><div><br></div><div><div class="gmail_quote">On Mon, Feb 13, 2012 at 12:17 PM, Tony Trinh <span dir="ltr"><<a href="mailto:tony19@gmail.com" target="_blank">tony19@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+1 !!<div><div><br><br><div class="gmail_quote">On Mon, Feb 13, 2012 at 11:47 AM, Chris Pratt <span dir="ltr"><<a href="mailto:thechrispratt@gmail.com" target="_blank">thechrispratt@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<font face="arial, helvetica, sans-serif">Sure, it uses an extension of the java.text.MessageFormat syntax that allows for unlimited formatted varargs, and allows using dot-notation to prevent evaluation of the methods until it's been deemed necessary. With the current libraries (all of them really), you have to evaluate all the javabeans that hold the data you are looking to log before it's decided whether to log the information or not. In other words:</font><div>
<font face="arial, helvetica, sans-serif"><br></font></div><div><div><font face="'courier new', monospace">log.<font color="#00007f">debug</font>(<font color="#007f00">"Loading Student ["</font> + sdnt.<font color="#00007f">getNumber</font>() + <font color="#007f00">"] "</font> + sdnt.<font color="#00007f">getName</font>() + <font color="#007f00">" Enrolled: "</font> +<font color="#0000ff"> new</font> <font color="#00007f">SimpleDateFormat</font>(<font color="#007f00">"yyyy-MM-dd"</font>).<font color="#00007f">format</font>(sdnt.<font color="#00007f">getEnrollmentDate</font>()));</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Means that a lot of work is done and discarded when the debug level on this file is set to info or less. SLF4j is a little better, but not much:</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><div><font face="'courier new', monospace">log.<font color="#00007f">debug</font>(<font color="#007f00">"Loading Student [{}] {} Enrolled: {}"</font>,<font color="#0000ff">new</font> <font color="#0000ff">Object</font>[] {sdnt.<font color="#00007f">getNumber</font>(),sdnt.<font color="#00007f">getName</font>(),<font color="#0000ff">new</font> <font color="#00007f">SimpleDateFormat</font>(<font color="#007f00">"yyyy-MM-dd"</font>).<font color="#00007f">format</font>(sdnt.<font color="#00007f">getEnrollmentDate</font>())});</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Yes, of course you could (and probably should) wrap each and every call to the log system in </font><font face="'courier new', monospace"><font color="#3333ff">if</font>(<font color="#000099">log</font>.isDebugEnabled()) {}</font><font face="arial, helvetica, sans-serif">. But we all know that is ugly and easy for Jr programmers to forget. My library puts off the evaluation until after it's been decided that the information is necessary, then efficiently outputs the message, like this:</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="'courier new', monospace">log.<font color="#00007f">debug</font>(<font color="#007f00">"Loading Student [{0.number}] {<a href="http://0.name" target="_blank">0.name</a>} Enrolled: {0.enrollmentDate,date,yyyy-MM-dd}"</font>,student);
</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">No muss, no fuss and the TextFormat utility is completely usable standalone (as well as the advanced dot-notation utilities).</font></div>
<span><font color="#888888">
<div><font face="arial, helvetica, sans-serif"> (*Chris*)</font></div></font></span></div><div><div><br></div></div></div></blockquote></div>
</div></div></blockquote></div><br></div>
</div></div><br></div></div><div>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></div></blockquote></div><br></div>
<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>