+1 !!<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">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 style><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 style><font face="arial, helvetica, sans-serif"><br></font></div><div style><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 style><font face="arial, helvetica, sans-serif"><br></font></div><div style><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 class="HOEnZb"><font color="#888888">

<div><font face="arial, helvetica, sans-serif">  (*Chris*)</font></div></font></span></div><div><div class="h5"><br></div></div></div></blockquote></div>