You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Naresh Sharma <na...@yahoo.com> on 2005/04/14 08:08:44 UTC

problem in logging with multiple files

Hi,

I want to send the log message to different log files
depending on the the package. e.g. package com.a log
message should go to A.log, package com.b should go to
B.log file.

I am able to do this through following configuration


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration
xmlns:log4j='http://jakarta.apache.org/log4j/'>
	
	<appender name="A1"
class="org.apache.log4j.RollingFileAppender">
		<!-- set the absolute path and log file name to
create. -->
		<param name="File" value="A.log"/>
        <param name="Append" value="true" />	    	
		<!-- set the max file size. --> 
		<param name="MaxFileSize" value="1024KB"/>
		<!-- set the number of files. -->
		<param name="MaxBackupIndex" value="10"/>
		<!-- LAYOUT SETUP-->
		<!-- set the pattern layout. -->
		<layout class="org.apache.log4j.PatternLayout">
		<!-- print the date in ISO 8601 format -->
			<param name ="ConversionPattern"
value="%d{dd-MMM-yyyy} %d{HH:mm:ss}      %p 
%c.%C{1}.%M()|%m%n"/>
		</layout>
	</appender>

	<appender name="A2"
class="org.apache.log4j.RollingFileAppender">
		<!-- set the absolute path and log file name to
create. -->
		<param name="File" value="B.log"/>
        <param name="Append" value="true" />	    	
		<!-- set the max file size. --> 
		<param name="MaxFileSize" value="1024KB"/>
		<!-- set the number of files. -->
		<param name="MaxBackupIndex" value="10"/>
		<!-- LAYOUT SETUP-->
		<!-- set the pattern layout. -->
		<layout class="org.apache.log4j.PatternLayout">
		<!-- print the date in ISO 8601 format -->
			<param name ="ConversionPattern"
value="%d{dd-MMM-yyyy} %d{HH:mm:ss}      %p 
%c.%C{1}.%M()|%m%n"/>
		</layout>
	</appender>

	<category name="com.a">
	  <priority value="debug" />
	  <appender-ref ref="A1" />
	</category>

	<category name="com.b">
	  <priority value="debug" />
	  <appender-ref ref="A2" />
	</category>	

	<root>
	   <priority value ="fatal" />
		<appender-ref ref="STDOUT" />
   	   <appender-ref ref="A1" />
	</root>
	
</log4j:configuration>


Here is the sample call i made to this logger

TestLogger.debug("com.a","Hi, i am calling from
com.a");		
TestLogger.debug("com.b","Hi, i am calling from
com.b");	

Above mentioned code causes it to log following 3
message in A.log 
	14-Apr-2005 11:28:36      DEBUG 
com.a.TestLogger.main()|Hi, i am calling from com.a
	14-Apr-2005 11:28:36      DEBUG 
com.b.TestLogger.main()|Hi, i am calling from com.b
	14-Apr-2005 11:28:36      DEBUG 
com.a.TestLogger.main()|Hi, i am calling from com.a

B.log get the following 

	14-Apr-2005 11:28:36      DEBUG 
com.b.TestLogger.main()|Hi, i am calling from com.b

I expect A.log file to get only one log message. This
is happening due to <root> tag in the log4j
configuration file. If i remove the following segment
from log4j configuration it works as desired

		<root>
		   <priority value ="fatal" />
		   <appender-ref ref="STDOUT" />
	   	   <appender-ref ref="A1" />
		</root>


Is this bug, or i am missing something?


Regards
Naresh


	
		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: problem in logging with multiple files

Posted by James Stauffer <st...@gmail.com>.
I would have written that as follows.  I don't know if the differences
are important or not.  The way that you have it configured, fatal
errors from both packages will go to appender A1.

        <logger name="com.a">
         <level value="debug" />
         <appender-ref ref="A1" />
       </category>

       <logger name="com.b">
         <level value="debug" />
         <appender-ref ref="A2" />
       </category>

       <root>
          <level value ="fatal" />
               <appender-ref ref="STDOUT" />
          <appender-ref ref="A1" />
       </root>



On 4/14/05, Naresh Sharma <na...@yahoo.com> wrote:
>         <category name="com.a">
>           <priority value="debug" />
>           <appender-ref ref="A1" />
>         </category>
> 
>         <category name="com.b">
>           <priority value="debug" />
>           <appender-ref ref="A2" />
>         </category>
> 
>         <root>
>            <priority value ="fatal" />
>                 <appender-ref ref="STDOUT" />
>            <appender-ref ref="A1" />
>         </root>
> 
> </log4j:configuration>

-- 
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org