logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From K Srinivas <ksrinivas_...@yahoo.co.in>
Subject Re: writing logs into multiple files
Date Sun, 02 Oct 2005 07:36:45 GMT



Hi,

please find below XML to log into multiple
destinations based on different packages.

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

<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/">    

<!-- appender for all packages -->
    <appender name="sriniFile"
class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="c:\\srini.log" />
        <layout
class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
value="[%t][%l]%m%n" />
        </layout>
    </appender>

<!-- appender for main package -->
    <appender name="mainFile"
class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="c:\\srini_main.log"
/>
        <layout
class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
value="[%t][%l]%m%n" />
        </layout>
    </appender>    
    
<!-- appender for pack1 package -->
    <appender name="pack1File"
class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="c:\\srini_pack1.log"
/>
        <layout
class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
value="[%t][%l]%m%n" />
        </layout>
    </appender>    
    
<!-- appender for pack2 package -->
    <appender name="pack2File"
class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="c:\\srini_pack2.log"
/>
        <layout
class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
value="[%t][%l]%m%n" />
        </layout>
        <filter
class="org.apache.log4j.varia.LevelMatchFilter">
		<param name="LevelToMatch" value="INFO" />
		<param name="AcceptOnMatch" value="false" />
        </filter>
        <filter
class="org.apache.log4j.varia.LevelMatchFilter">
		<param name="LevelToMatch" value="WARN" />
		<param name="AcceptOnMatch" value="false" />
        </filter>        
        <filter
class="org.apache.log4j.varia.LevelMatchFilter">
		<param name="LevelToMatch" value="ERROR" />
		<param name="AcceptOnMatch" value="false" />
        </filter>
        <filter
class="org.apache.log4j.varia.LevelMatchFilter">
		<param name="LevelToMatch" value="FATAL" />
		<param name="AcceptOnMatch" value="false" />
        </filter>        
    </appender>    
    
<!-- logger for all the packages -->    
    <logger name="srini" additivity="false">
        <level value="warn" />
        <appender-ref ref="sriniFile"  />        
    </logger>    
    
<!-- logger for all srini.main package -->    
    <logger name="srini.main" additivity="false">
        <level value="debug" />
        <appender-ref ref="mainFile" />
    </logger>    

<!-- logger for all srini.pack1 package -->    
    <logger name="srini.pack1" additivity="false">
        <level value="debug" />
        <appender-ref ref="pack1File" />
    </logger>    

<!-- logger for all srini.pack2 package -->    
    <logger name="srini.pack2" additivity="false">
        <level value="debug" />       
        <appender-ref ref="pack2File" />
    </logger>

</log4j:configuration>


LevlMatchFilter is used to filter the level of the
logger.  otherwise basic level rule is being followed.

please correct me if i am wrong

But one strange thing is, i have done this examples
and successfully executed the sample programs on
windows xp operating system.  i just put
log4j-1.2.8.jar in the class path.

Now when i am trying to run the same on windows 2000
professional OS, i am getting an error saying 

cannot access org.w3c.dom.Element
file org\w3c\dom\Element.class not found
                DOMConfigurator.configure(args[0]);

i have installed same JVM (j2sdk1.4.2_04) in both the
machines.

please let me know what can be the issue.

srinivas

















--- rusty+commons <rusty+commons@grunt.berkeley.edu>
wrote:

> I use the following.  Is using the 
> org.apache.log4j.varia.LevelMatchFilter a better way
> log to different 
> places?
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
> 
> <log4j:configuration
> xmlns:log4j="http://jakarta.apache.org/log4j/">
>     <appender name="CONS"
> class="org.apache.log4j.ConsoleAppender">
>         <layout
> class="org.apache.log4j.PatternLayout">
>             <param name="ConversionPattern"
> value="%M %m%n" />
>         </layout>
>     </appender>
> 
>     <!-- param entries must come before layout
> entry!?          -->
>     <appender name="FILE"
> class="org.apache.log4j.RollingFileAppender">
>         <param name="File" value="/var/tmp/cars.log"
> />
>         <param name="MaxFileSize" value="300kb" />
>         <param name="MaxBackupIndex" value="9" />
>         <layout
> class="org.apache.log4j.PatternLayout">
>             <param name="ConversionPattern"
> value="%p: %d [%C %M] %m%n" />
>         </layout>
>     </appender>
> 
>     <!-- example of how to change the level and
> appender        -->
>     <!-- for a specific class.                      
>            -->
>     <logger name="props.PropsBase">
>         <level value="warn" />
>         <appender-ref ref="FILE" />
>     </logger>
> 
>     <!-- example of how to change the level and
> appender        -->
>     <!-- for a specific class.                      
>            -->
>     <logger name="org.apache.commons">
>         <level value="warn" />
>         <appender-ref ref="CONS" />
>         <appender-ref ref="FILE" />
>     </logger>
> 
>     <root>
>         <level value="debug" />
>         <appender-ref ref="CONS" />
>         <appender-ref ref="FILE" />
>     </root>
> </log4j:configuration>
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail:
> log4j-user-help@logging.apache.org
> 
> 



		
__________________________________________________________ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com

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


Mime
View raw message