<?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: Log4j MDC (Mapped Diagnostic Context) : Example code</title>
	<atom:link href="http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/</link>
	<description>Java, web and design</description>
	<lastBuildDate>Sun, 20 May 2012 11:47:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: shrikanth</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2314</link>
		<dc:creator>shrikanth</dc:creator>
		<pubDate>Fri, 18 May 2012 10:24:45 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2314</guid>
		<description>i forget to mention tht i am setting MDC.put(&quot;userName&quot;,&quot;srkth&quot;); inside public staic void main()...so can it be done inside static methods..is tht the problem</description>
		<content:encoded><![CDATA[<p>i forget to mention tht i am setting MDC.put(&#8220;userName&#8221;,&#8221;srkth&#8221;); inside public staic void main()&#8230;so can it be done inside static methods..is tht the problem</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shrikanth</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2313</link>
		<dc:creator>shrikanth</dc:creator>
		<pubDate>Fri, 18 May 2012 09:02:18 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2313</guid>
		<description>hello Veera,
I used the MDC concept as u said in standalone application.But somehow its not printing the username..i used MDC.put(&quot;userName&quot;,&quot;srkth&quot;); in main program. then modified xml file as below..am i doing something wrong..i have blown my head off..cant figure out wht the problem is


&lt;!--

	appender to log all the debug and above levels to the console in the conversion pattern %d{ABSOLUTE} [%t] %-5p %c - %m%n
    --&gt;
	

	    
	
    

	&lt;!--appender to log all the error and above levels to the file in the conversion pattern %d{ABSOLUTE} [%t] %-5p %c - %m%n--&gt;
    
         
        
		

        
        
        
        
    
        
        

     
		
	&lt;!--set root level as error--&gt;	
    
        
        
        
    
</description>
		<content:encoded><![CDATA[<p>hello Veera,<br />
I used the MDC concept as u said in standalone application.But somehow its not printing the username..i used MDC.put(&#8220;userName&#8221;,&#8221;srkth&#8221;); in main program. then modified xml file as below..am i doing something wrong..i have blown my head off..cant figure out wht the problem is</p>
<p><!--</p>
<p>	appender to log all the debug and above levels to the console in the conversion pattern %d{ABSOLUTE} [%t] %-5p %c - %m%n<br />
    --></p>
<p>	<!--appender to log all the error and above levels to the file in the conversion pattern %d{ABSOLUTE} [%t] %-5p %c - %m%n--></p>
<p>	<!--set root level as error-->	</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Veera</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2234</link>
		<dc:creator>Veera</dc:creator>
		<pubDate>Fri, 27 Apr 2012 17:07:09 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2234</guid>
		<description>care to explain?</description>
		<content:encoded><![CDATA[<p>care to explain?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mperroul</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2232</link>
		<dc:creator>mperroul</dc:creator>
		<pubDate>Fri, 27 Apr 2012 11:47:40 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2232</guid>
		<description>It don&#039;t work and cannot work dues to static method !</description>
		<content:encoded><![CDATA[<p>It don&#8217;t work and cannot work dues to static method !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kalaivani</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2149</link>
		<dc:creator>kalaivani</dc:creator>
		<pubDate>Tue, 03 Apr 2012 12:20:32 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2149</guid>
		<description>Hi veera,

if i modified my_log4j.xml while running the application. the MDC list values are cleared..how to reset it without restarting my application

Do you have any idea for this

Thanks in advance</description>
		<content:encoded><![CDATA[<p>Hi veera,</p>
<p>if i modified my_log4j.xml while running the application. the MDC list values are cleared..how to reset it without restarting my application</p>
<p>Do you have any idea for this</p>
<p>Thanks in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tarik Makhija</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2129</link>
		<dc:creator>Tarik Makhija</dc:creator>
		<pubDate>Thu, 29 Mar 2012 16:00:35 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2129</guid>
		<description>The Setting in ApacheLog4jcfg.xml is  
appender name=&quot;APPLOGFILE&quot; class=&quot;mypackage.KeyFileAppender
		param name=&quot;File&quot; value=&quot;APP.log&quot;
		param name=&quot;Append&quot; value=&quot;true&quot;
		param name=&quot;ContextKey&quot; value=&quot;requestID&quot;
		param name=&quot;MaxFileSize&quot; value=&quot;20MB&quot;
		param name=&quot;MaxBackupIndex&quot; value=&quot;30&quot;
		layout class=&quot;org.apache.log4j.PatternLayout&quot;
			param name=&quot;ConversionPattern&quot; value=&quot;%d;%r;%p;[%c] -- %m%n&quot;
		layout
appender</description>
		<content:encoded><![CDATA[<p>The Setting in ApacheLog4jcfg.xml is<br />
appender name=&#8221;APPLOGFILE&#8221; class=&#8221;mypackage.KeyFileAppender<br />
		param name=&#8221;File&#8221; value=&#8221;APP.log&#8221;<br />
		param name=&#8221;Append&#8221; value=&#8221;true&#8221;<br />
		param name=&#8221;ContextKey&#8221; value=&#8221;requestID&#8221;<br />
		param name=&#8221;MaxFileSize&#8221; value=&#8221;20MB&#8221;<br />
		param name=&#8221;MaxBackupIndex&#8221; value=&#8221;30&#8243;<br />
		layout class=&#8221;org.apache.log4j.PatternLayout&#8221;<br />
			param name=&#8221;ConversionPattern&#8221; value=&#8221;%d;%r;%p;[%c] &#8212; %m%n&#8221;<br />
		layout<br />
appender</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tarik Makhija</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2128</link>
		<dc:creator>Tarik Makhija</dc:creator>
		<pubDate>Thu, 29 Mar 2012 15:58:28 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2128</guid>
		<description>We are using Weblogic Integration 9.2 and Log4j for logging the application logs
We have a commonLogger Class which extends Log4j Logger and return a static instance of Log4j Logger for each Weblogic JPD class.

In Our Application , Each JPD class is using CommonLogger Class to return the static instance of the Logger object such as  private static CommonLogger logger = CommonLogger.getInstance(ClassX.class);

Our Application is used by Multiple testers.
All the Application Logs go to common Log file APP.log
So each tester have to scroll down through the file to find his/her each piece of log.

Our goal is to generate dynamic log for each and every tester so as to save time.

For Weblogic 9.2 Server We have file called “config.xml” , This File gets updated when anything is changed or updated from the Weblogic Console.

In this config.xml File , We have a Server setting like below :
-Dlog4j.configuration=file:/path/apacheLog4jCfg.xml

This Setting is referring to File called apacheLog4jCfg.xml Which means that Weblogic Server is using apache Log4j to do the logging.

In apacheLog4jCfg.xml File , We have the setting like below : 
I am using KeyFileAppender to achieve this where In ApacheLog4jcfg.xml , I have the setting like below : 

&lt;!--application logfile --&gt;
	
		
		
		
		&lt;!----&gt;
		&lt;!----&gt;
		
			
		
	

In this Setting where appender name is APPLOGFILE class is mypackage.KeyFileAppender
param name is File and value is APP.log , this will log all the application logs to the File APP.log
i.e All the testers will hit the application and all the logs will get stored in the File “APP.log”

To generate the dynamic logs we define the following setting in Apachelog4jcfg.xml
We have ContextKey defined in the ApacheLog4jcfg.xml setting whose value is requestID.
This requestID we are using as key in MDC as MDC.put(&quot;requestID&quot;, RuntimeStringValue);
this RuntimeStringValue will get Appended to the APP.log file.
Suppose the Runtime value is X123
So log file should get generated like APP.X123.log

We are using MDC.put(&quot;requestID&quot;, RuntimeStringValue); in CommonLogger Class in the getInstance Method as below :

public static CommonLogger getInstance(Object className) {
                                CommonLogger CommonLogger = new CommonLogger();
                                
                                if (className instanceof String) {
                                                CommonLogger.logger = Logger.getLogger((String) className);
                                } else {
                                                CommonLogger.logger = Logger.getLogger((Class) className);
                                }
                                
                                if(RuntimeStringValue != null){
                                                MDC.put(&quot;requestID&quot;,RuntimeStringValue);
                                                                        
                                }
                                return CommonLogger;
                }


But the problem, which we are facing is that we are able to generate the Log File for first User request.
In the Second User request the logs are going to previously created log file only.

I feel it is due to static keyword present in CommonLogger getInstance(Object className) Method.

The another issue is if we remove static keyword from this method , then all the classes in the application will get affected as they are using the java syntax like private static CommonLogger logger = CommonLogger.getInstance(SomeClassX.class);

I have a questions below :
Q1 : So Using log4j , Is it possible that for each Tester testing the application , a separate log file should be created, So that he/she can see their own set of logs ?

Q2 :  Can we use MDC.put for entire application or we have to provide MDC.put for each and every java class file in the application ?</description>
		<content:encoded><![CDATA[<p>We are using Weblogic Integration 9.2 and Log4j for logging the application logs<br />
We have a commonLogger Class which extends Log4j Logger and return a static instance of Log4j Logger for each Weblogic JPD class.</p>
<p>In Our Application , Each JPD class is using CommonLogger Class to return the static instance of the Logger object such as  private static CommonLogger logger = CommonLogger.getInstance(ClassX.class);</p>
<p>Our Application is used by Multiple testers.<br />
All the Application Logs go to common Log file APP.log<br />
So each tester have to scroll down through the file to find his/her each piece of log.</p>
<p>Our goal is to generate dynamic log for each and every tester so as to save time.</p>
<p>For Weblogic 9.2 Server We have file called “config.xml” , This File gets updated when anything is changed or updated from the Weblogic Console.</p>
<p>In this config.xml File , We have a Server setting like below :<br />
-Dlog4j.configuration=file:/path/apacheLog4jCfg.xml</p>
<p>This Setting is referring to File called apacheLog4jCfg.xml Which means that Weblogic Server is using apache Log4j to do the logging.</p>
<p>In apacheLog4jCfg.xml File , We have the setting like below :<br />
I am using KeyFileAppender to achieve this where In ApacheLog4jcfg.xml , I have the setting like below : </p>
<p><!--application logfile --></p>
<p>		&lt;!&#8212;-&gt;<br />
		&lt;!&#8212;-&gt;</p>
<p>In this Setting where appender name is APPLOGFILE class is mypackage.KeyFileAppender<br />
param name is File and value is APP.log , this will log all the application logs to the File APP.log<br />
i.e All the testers will hit the application and all the logs will get stored in the File “APP.log”</p>
<p>To generate the dynamic logs we define the following setting in Apachelog4jcfg.xml<br />
We have ContextKey defined in the ApacheLog4jcfg.xml setting whose value is requestID.<br />
This requestID we are using as key in MDC as MDC.put(&#8220;requestID&#8221;, RuntimeStringValue);<br />
this RuntimeStringValue will get Appended to the APP.log file.<br />
Suppose the Runtime value is X123<br />
So log file should get generated like APP.X123.log</p>
<p>We are using MDC.put(&#8220;requestID&#8221;, RuntimeStringValue); in CommonLogger Class in the getInstance Method as below :</p>
<p>public static CommonLogger getInstance(Object className) {<br />
                                CommonLogger CommonLogger = new CommonLogger();</p>
<p>                                if (className instanceof String) {<br />
                                                CommonLogger.logger = Logger.getLogger((String) className);<br />
                                } else {<br />
                                                CommonLogger.logger = Logger.getLogger((Class) className);<br />
                                }</p>
<p>                                if(RuntimeStringValue != null){<br />
                                                MDC.put(&#8220;requestID&#8221;,RuntimeStringValue);</p>
<p>                                }<br />
                                return CommonLogger;<br />
                }</p>
<p>But the problem, which we are facing is that we are able to generate the Log File for first User request.<br />
In the Second User request the logs are going to previously created log file only.</p>
<p>I feel it is due to static keyword present in CommonLogger getInstance(Object className) Method.</p>
<p>The another issue is if we remove static keyword from this method , then all the classes in the application will get affected as they are using the java syntax like private static CommonLogger logger = CommonLogger.getInstance(SomeClassX.class);</p>
<p>I have a questions below :<br />
Q1 : So Using log4j , Is it possible that for each Tester testing the application , a separate log file should be created, So that he/she can see their own set of logs ?</p>
<p>Q2 :  Can we use MDC.put for entire application or we have to provide MDC.put for each and every java class file in the application ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Venkat</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2105</link>
		<dc:creator>Venkat</dc:creator>
		<pubDate>Wed, 21 Mar 2012 16:20:03 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2105</guid>
		<description>What if I don&#039;t remove the variable from MDC ? Add same value again because web application make lots of other calls within that session and assigns the same user name again in the filter.</description>
		<content:encoded><![CDATA[<p>What if I don&#8217;t remove the variable from MDC ? Add same value again because web application make lots of other calls within that session and assigns the same user name again in the filter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafael</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2088</link>
		<dc:creator>Rafael</dc:creator>
		<pubDate>Fri, 16 Mar 2012 20:43:09 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2088</guid>
		<description>Hi Veera
do I need to set MDC parameters every time a request is sent ? 
Isn&#039;t there a way to set MDC only once, say, when user has just logged in and keep these values accessible for any class until session expires or user logs out ?</description>
		<content:encoded><![CDATA[<p>Hi Veera<br />
do I need to set MDC parameters every time a request is sent ?<br />
Isn&#8217;t there a way to set MDC only once, say, when user has just logged in and keep these values accessible for any class until session expires or user logs out ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Veera</title>
		<link>http://veerasundar.com/blog/2009/11/log4j-mdc-mapped-diagnostic-context-example-code/#comment-2072</link>
		<dc:creator>Veera</dc:creator>
		<pubDate>Thu, 15 Mar 2012 06:24:33 +0000</pubDate>
		<guid isPermaLink="false">http://veerasundar.com/blog/?p=952#comment-2072</guid>
		<description>I never tried it in clustered environment.. But I assume there&#039;s no need for any additional settings... the default options should work fine.</description>
		<content:encoded><![CDATA[<p>I never tried it in clustered environment.. But I assume there&#8217;s no need for any additional settings&#8230; the default options should work fine.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

