[prev in list] [next in list] [prev in thread] [next in thread] 

List:       logback-user
Subject:    Re: [logback-user] Compiler selecting wrong Logger method
From:       Chris Pratt <thechrispratt () gmail ! com>
Date:       2012-02-13 20:01:21
Message-ID: CAALdY0wXbnuxG3W_GCBzX-uT1sUFnaPk_gehWiFVtx6GitK8zw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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.
  (*Chris*)

On Mon, Feb 13, 2012 at 11:09 AM, Tony Trinh <tony19@gmail.com> wrote:

> 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.
>
> -Tony
>
> On Mon, Feb 13, 2012 at 1:10 PM, Chris Pratt <thechrispratt@gmail.com>wrote:
>
>> 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.
>>    (*Chris*)
>>
>>
>> On Mon, Feb 13, 2012 at 9:44 AM, Tony Trinh <tony19@gmail.com> wrote:
>>
>>> 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:
>>>
>>>
>>> log.debug("Loading Student [{0.number}] {0.name} Enrolled:
>>> {0.enrollmentDate,date,yyyy-MM-dd}",student);
>>>
>>> and down the road, someone decides to remove the number field from the Student
>>> 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.
>>>
>>>
>>> On Mon, Feb 13, 2012 at 12:35 PM, Chris Pratt <thechrispratt@gmail.com>wrote:
>>>
>>>> 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.
>>>>    (*Chris*)
>>>>
>>>> On Mon, Feb 13, 2012 at 9:24 AM, Tony Trinh <tony19@gmail.com> wrote:
>>>>
>>>>> 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?
>>>>>
>>>>> -Tony
>>>>>
>>>>> On Mon, Feb 13, 2012 at 12:17 PM, Tony Trinh <tony19@gmail.com> wrote:
>>>>>
>>>>>> +1 !!
>>>>>>
>>>>>>
>>>>>> On Mon, Feb 13, 2012 at 11:47 AM, Chris Pratt <
>>>>>> thechrispratt@gmail.com> wrote:
>>>>>>
>>>>>>> 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:
>>>>>>>
>>>>>>> log.debug("Loading Student [" + sdnt.getNumber() + "] " + sdnt.
>>>>>>> getName() + " Enrolled: " + new SimpleDateFormat("yyyy-MM-dd").
>>>>>>> format(sdnt.getEnrollmentDate()));
>>>>>>>
>>>>>>> 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:
>>>>>>>
>>>>>>> log.debug("Loading Student [{}] {} Enrolled: {}",new Object[] {sdnt.
>>>>>>> getNumber(),sdnt.getName(),new SimpleDateFormat("yyyy-MM-dd").format
>>>>>>> (sdnt.getEnrollmentDate())});
>>>>>>>
>>>>>>> Yes, of course you could (and probably should) wrap each and every
>>>>>>> call to the log system in if(log.isDebugEnabled()) {}.  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:
>>>>>>>
>>>>>>> log.debug("Loading Student [{0.number}] {0.name} Enrolled:
>>>>>>> {0.enrollmentDate,date,yyyy-MM-dd}",student);
>>>>>>>
>>>>>>> No muss, no fuss and the TextFormat utility is completely usable
>>>>>>> standalone (as well as the advanced dot-notation utilities).
>>>>>>>    (*Chris*)
>>>>>>>
>>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Logback-user mailing list
>>>>> Logback-user@qos.ch
>>>>> http://mailman.qos.ch/mailman/listinfo/logback-user
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Logback-user mailing list
>>>> Logback-user@qos.ch
>>>> http://mailman.qos.ch/mailman/listinfo/logback-user
>>>>
>>>
>>>
>>> _______________________________________________
>>> Logback-user mailing list
>>> Logback-user@qos.ch
>>> http://mailman.qos.ch/mailman/listinfo/logback-user
>>>
>>
>>
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user@qos.ch
>> http://mailman.qos.ch/mailman/listinfo/logback-user
>>
>
>
> _______________________________________________
> Logback-user mailing list
> Logback-user@qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>

[Attachment #5 (text/html)]

I like the idea of making it obvious when there is no value for an existing field \
(i.e. &quot;null&quot;) and when there is no way to get to the field (e.g. \
&quot;???0.number???&quot;).  I&#39;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">&lt;<a \
href="mailto:tony19@gmail.com">tony19@gmail.com</a>&gt;</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 &quot;null&quot; (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">&lt;<a href="mailto:thechrispratt@gmail.com" \
target="_blank">thechrispratt@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">




That&#39;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 \
&quot;null&quot; for that value, which isn&#39;t as helpful as it could be.  Maybe I \
could have it log &quot;missing value:0.number&quot; 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">&lt;<a href="mailto:tony19@gmail.com" \
target="_blank">tony19@gmail.com</a>&gt;</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 &quot;new &amp; \
improved&quot; formatted string. If, for example, I had this formatted \
string:<div><br><br><span style="font-family:&#39;courier \
new&#39;,monospace">log.</span><font color="#00007f" style="font-family:&#39;courier \
new&#39;,monospace">debug</font><span style="font-family:&#39;courier \
new&#39;,monospace">(</span><font color="#007f00" style="font-family:&#39;courier \
new&#39;,monospace">&quot;Loading Student [{0.number}] {<a href="http://0.name/" \
target="_blank">0.name</a>} Enrolled: \
{0.enrollmentDate,date,yyyy-MM-dd}&quot;</font><span style="font-family:&#39;courier \
new&#39;,monospace">,student);</span> <br>








<br></div>and down the road, someone decides to remove the <font face="&#39;courier \
new&#39;, monospace">number </font>field from the <font face="&#39;courier new&#39;, \
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">&lt;<a href="mailto:thechrispratt@gmail.com" \
target="_blank">thechrispratt@gmail.com</a>&gt;</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 &quot;new &amp; improved&quot; 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">&lt;<a href="mailto:tony19@gmail.com" \
target="_blank">tony19@gmail.com</a>&gt;</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&#39;m a fan of this idea (if you couldn&#39;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">&lt;<a href="mailto:tony19@gmail.com" \
target="_blank">tony19@gmail.com</a>&gt;</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">&lt;<a href="mailto:thechrispratt@gmail.com" \
target="_blank">thechrispratt@gmail.com</a>&gt;</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&#39;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&#39;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="&#39;courier new&#39;, monospace">log.<font color="#00007f">debug</font>(<font \
color="#007f00">&quot;Loading Student [&quot;</font> + sdnt.<font \
color="#00007f">getNumber</font>() + <font color="#007f00">&quot;] &quot;</font> + \
sdnt.<font color="#00007f">getName</font>() + <font color="#007f00">&quot; Enrolled: \
&quot;</font> +<font color="#0000ff"> new</font> <font \
color="#00007f">SimpleDateFormat</font>(<font \
color="#007f00">&quot;yyyy-MM-dd&quot;</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="&#39;courier new&#39;, monospace">log.<font color="#00007f">debug</font>(<font \
color="#007f00">&quot;Loading Student [{}] {} Enrolled: {}&quot;</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">&quot;yyyy-MM-dd&quot;</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="&#39;courier \
new&#39;, 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&#39;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="&#39;courier new&#39;, monospace">log.<font color="#00007f">debug</font>(<font \
color="#007f00">&quot;Loading Student [{0.number}] {<a href="http://0.name" \
target="_blank">0.name</a>} Enrolled: \
{0.enrollmentDate,date,yyyy-MM-dd}&quot;</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>




_______________________________________________
Logback-user mailing list
Logback-user@qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-user

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic