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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
