<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Logging with log4J isDebugEnabled</title>
	<atom:link href="http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/</link>
	<description>Another bit in the wall</description>
	<lastBuildDate>Tue, 15 Jun 2010 06:04:50 -0700</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Shaaf Shah</title>
		<link>http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/comment-page-1/#comment-1028</link>
		<dc:creator>Shaaf Shah</dc:creator>
		<pubDate>Thu, 20 Aug 2009 08:22:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaafshah.com/?p=248#comment-1028</guid>
		<description>&lt;a href=&quot;#comment-1018&quot; rel=&quot;nofollow&quot;&gt;@Ahmed Ali &lt;/a&gt; 
Yes this certainly sounds very interesting.</description>
		<content:encoded><![CDATA[<p><a href="#comment-1018" rel="nofollow">@Ahmed Ali </a><br />
Yes this certainly sounds very interesting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahmed Ali</title>
		<link>http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/comment-page-1/#comment-1018</link>
		<dc:creator>Ahmed Ali</dc:creator>
		<pubDate>Sun, 16 Aug 2009 09:34:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaafshah.com/?p=248#comment-1018</guid>
		<description>I agree with your suggestion of enclosing the debug call in the log.isDebugEnabled() and you can keep the result as suggested by @Sébastien 

I am not sure about how the SLF4J solved that issue, but for the reference check the following link. i have copied the text below that explains how you can improve the performance by using the SLF4J.

http://www.slf4.org/faq.html#logging_performance 
------------------------------------------------------------------------------
What is the fastest way of (not) logging?

    SLF4J supports an advanced feature called parameterized logging which can significantly boost logging performance for disabled logging statement.

    For some Logger logger, writing,

    logger.debug(&quot;Entry number: &quot; + i + &quot; is &quot; + String.valueOf(entry[i]));

    incurs the cost of constructing the message parameter, that is converting both integer i and entry[i] to a String, and concatenating intermediate strings. This, regardless of whether the message will be logged or not.

    One possible way to avoid the cost of parameter construction is by surrounding the log statement with a test. Here is an example.

    if(logger.isDebugEnabled()) {
      logger.debug(&quot;Entry number: &quot; + i + &quot; is &quot; + String.valueOf(entry[i]));
    }

    This way you will not incur the cost of parameter construction if debugging is disabled for logger. On the other hand, if the logger is enabled for the DEBUG level, you will incur the cost of evaluating whether the logger is enabled or not, twice: once in debugEnabled and once in debug. This is an insignificant overhead because evaluating a logger takes less than 1% of the time it takes to actually log a statement.

Better yet, use parameterized messages

    There exists a very convenient alternative based on message formats. Assuming entry is an object, you can write:

    Object entry = new SomeObject();
    logger.debug(&quot;The entry is {}.&quot;, entry);

    After evaluating whether to log or not, and only if the decision is affirmative, will the logger implementation format the message and replace the &#039;{}&#039; pair with the string value of entry. In other words, this form does not incur the cost of parameter construction in case the log statement is disabled.

  ...
  ...</description>
		<content:encoded><![CDATA[<p>I agree with your suggestion of enclosing the debug call in the log.isDebugEnabled() and you can keep the result as suggested by @Sébastien </p>
<p>I am not sure about how the SLF4J solved that issue, but for the reference check the following link. i have copied the text below that explains how you can improve the performance by using the SLF4J.</p>
<p><a href="http://www.slf4.org/faq.html#logging_performance" rel="nofollow">http://www.slf4.org/faq.html#logging_performance</a><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
What is the fastest way of (not) logging?</p>
<p>    SLF4J supports an advanced feature called parameterized logging which can significantly boost logging performance for disabled logging statement.</p>
<p>    For some Logger logger, writing,</p>
<p>    logger.debug(&#8220;Entry number: &#8221; + i + &#8221; is &#8221; + String.valueOf(entry[i]));</p>
<p>    incurs the cost of constructing the message parameter, that is converting both integer i and entry[i] to a String, and concatenating intermediate strings. This, regardless of whether the message will be logged or not.</p>
<p>    One possible way to avoid the cost of parameter construction is by surrounding the log statement with a test. Here is an example.</p>
<p>    if(logger.isDebugEnabled()) {<br />
      logger.debug(&#8220;Entry number: &#8221; + i + &#8221; is &#8221; + String.valueOf(entry[i]));<br />
    }</p>
<p>    This way you will not incur the cost of parameter construction if debugging is disabled for logger. On the other hand, if the logger is enabled for the DEBUG level, you will incur the cost of evaluating whether the logger is enabled or not, twice: once in debugEnabled and once in debug. This is an insignificant overhead because evaluating a logger takes less than 1% of the time it takes to actually log a statement.</p>
<p>Better yet, use parameterized messages</p>
<p>    There exists a very convenient alternative based on message formats. Assuming entry is an object, you can write:</p>
<p>    Object entry = new SomeObject();<br />
    logger.debug(&#8220;The entry is {}.&#8221;, entry);</p>
<p>    After evaluating whether to log or not, and only if the decision is affirmative, will the logger implementation format the message and replace the &#8216;{}&#8217; pair with the string value of entry. In other words, this form does not incur the cost of parameter construction in case the log statement is disabled.</p>
<p>  &#8230;<br />
  &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shaaf Shah</title>
		<link>http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/comment-page-1/#comment-1017</link>
		<dc:creator>Shaaf Shah</dc:creator>
		<pubDate>Sun, 16 Aug 2009 08:25:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaafshah.com/?p=248#comment-1017</guid>
		<description>@Sébastien Yes that certainly is a good option since we wont have to make the call again and again. Especially for instance we heavily are doing alot debug logging.</description>
		<content:encoded><![CDATA[<p>@Sébastien Yes that certainly is a good option since we wont have to make the call again and again. Especially for instance we heavily are doing alot debug logging.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shaaf Shah</title>
		<link>http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/comment-page-1/#comment-1016</link>
		<dc:creator>Shaaf Shah</dc:creator>
		<pubDate>Sun, 16 Aug 2009 08:24:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaafshah.com/?p=248#comment-1016</guid>
		<description>@Alvin, @David If the thought is that the getXMLText() creates an expensive message for no purpose if isDebugEnabled is not enabled, How would SLF4J solve that?</description>
		<content:encoded><![CDATA[<p>@Alvin, @David If the thought is that the getXMLText() creates an expensive message for no purpose if isDebugEnabled is not enabled, How would SLF4J solve that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alvin</title>
		<link>http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/comment-page-1/#comment-1015</link>
		<dc:creator>alvin</dc:creator>
		<pubDate>Sun, 16 Aug 2009 01:41:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaafshah.com/?p=248#comment-1015</guid>
		<description>This is still an issue with log4j however log4j&#039;s successor - logback supports parameterized logging. So instead you would do something like - log.debug(&quot;XML {}&quot;, Tree.getXMLText());.</description>
		<content:encoded><![CDATA[<p>This is still an issue with log4j however log4j&#8217;s successor &#8211; logback supports parameterized logging. So instead you would do something like &#8211; log.debug(&#8220;XML {}&#8221;, Tree.getXMLText());.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Castañeda - davidecr</title>
		<link>http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/comment-page-1/#comment-1014</link>
		<dc:creator>David Castañeda - davidecr</dc:creator>
		<pubDate>Sat, 15 Aug 2009 20:58:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaafshah.com/?p=248#comment-1014</guid>
		<description>See:

log5j
or
http://www.slf4j.org/manual.html#typical_usage</description>
		<content:encoded><![CDATA[<p>See:</p>
<p>log5j<br />
or<br />
<a href="http://www.slf4j.org/manual.html#typical_usage" rel="nofollow">http://www.slf4j.org/manual.html#typical_usage</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sébastien</title>
		<link>http://www.shaafshah.com/2009/08/12/logging-with-log4j-isdebugenabled/comment-page-1/#comment-1013</link>
		<dc:creator>Sébastien</dc:creator>
		<pubDate>Sat, 15 Aug 2009 16:30:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaafshah.com/?p=248#comment-1013</guid>
		<description>What do you think of keeping the result of isDebugEnabled() ?

private static final Log log = ...
private static final boolean debugEnabled = log.isDebugEnabled();

/* instructions */
if(debugEnabled) {
    log.debug(&quot;hey&quot;);
}
/* instructions */
if(debugEnabled) {
    log.debug(&quot;ho&quot;);
}
/* instructions */
if(debugEnabled) {
    log.debug(&quot;foo&quot;);
}</description>
		<content:encoded><![CDATA[<p>What do you think of keeping the result of isDebugEnabled() ?</p>
<p>private static final Log log = &#8230;<br />
private static final boolean debugEnabled = log.isDebugEnabled();</p>
<p>/* instructions */<br />
if(debugEnabled) {<br />
    log.debug(&#8220;hey&#8221;);<br />
}<br />
/* instructions */<br />
if(debugEnabled) {<br />
    log.debug(&#8220;ho&#8221;);<br />
}<br />
/* instructions */<br />
if(debugEnabled) {<br />
    log.debug(&#8220;foo&#8221;);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
