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 ra...@iflexsolutions.com on 2003/12/10 15:43:34 UTC

log4j.xml configuration help


> Hi ,
> 
> I need help as i am new in using log4j.xml . 
> 
> My requirement is 
> 
> 1)When application uses INFO level , all the logs of the application should go into 1 log file ( say a.log)
> 2)when application uses DEBUG, ERROR ,FATAL level all logs of the application should go into another log file ( say b.log)
> 
> 
> Also log files path can be configurable and if file not exists can be created  . I am using log4j.xml not the lo4j.properties .
> 
> Pls suggest ,
> 
> ravindra 
> 


DISCLAIMER:
This message contains privileged and confidential information and is intended only for the individual named.If you are not the intended recipient you should not disseminate,distribute,store,print, copy or deliver this message.Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted,corrupted,lost,destroyed,arrive late or incomplete or contain viruses.The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version.

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


Re: log4j.xml configuration help

Posted by Adam Vainder <ad...@lexi.com>.
Since you're using the xml properties, set up 2 different loggers, and 
then attach filters to them.

Keep in mind that when attaching multiple filters to the same logger, 
that if the statement fails one filter, it will pass down to the next. A 
denial by a filter does not necessarily mean that the message is thrown 
away, the message just fails that filter and goes onto the next one 
(except in the case of DenyAllFilter). Which is why it's always safest 
to have a "DenyAllFilter" at the bottom of the list to catch the 
stragglers.

The filters you would need for this specific project are in the log4j 
package already.

e.g.

<log4j:configuration>
   <appender name="infoLogsFile" class="org.apache.log4j.FileAppender">
      <layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{MM-dd-
yyyy HH:mm:ss} %-5p %c - %m%n"/>
      </layout>
      <param name="file" value="info_messages.log"/>
      <filter class="org.apache.log4j.varia.LevelMatchFilter">
			<param name="LevelToMatch" value="INFO"/>
			<param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.DenyAllFilter"/>
  </appender>

  <appender name="otherLogsFile" class="org.apache.log4j.FileAppender">
      <layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{MM-dd-
yyyy HH:mm:ss} %-5p %c - %m%n"/>
      </layout>
      <param name="file" value="other_messages.log"/>
      <filter class="org.apache.log4j.varia.LevelMatchFilter">
			<param name="LevelToMatch" value="DEBUG"/>
			<param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.LevelRangeFilter">
			<param name="LevelMin" value="ERROR"/>
			<param name="LevelMax" value="FATAL"/>
			<param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.DenyAllFilter"/>
  </appender>

  <root>
		<priority value="ALL"/>
		<appender-ref ref="infoLogsFile"/>		
                <appender-ref ref="otherLogsFile"/>
  </root>
</log4j:configuration>

-----Original Message-----
From: <ra...@iflexsolutions.com>
To: <lo...@jakarta.apache.org>
Date: Wed, 10 Dec 2003 20:13:34 +0530
Subject: log4j.xml configuration help

> 
> 
> > Hi ,
> > 
> > I need help as i am new in using log4j.xml . 
> > 
> > My requirement is 
> > 
> > 1)When application uses INFO level , all the logs of the application
> should go into 1 log file ( say a.log)
> > 2)when application uses DEBUG, ERROR ,FATAL level all logs of the
> application should go into another log file ( say b.log)
> > 
> > 
> > Also log files path can be configurable and if file not exists can be
> created  . I am using log4j.xml not the lo4j.properties .
> > 
> > Pls suggest ,
> > 
> > ravindra 
> > 
> 
> 
> DISCLAIMER:
> This message contains privileged and confidential information and is
> intended only for the individual named.If you are not the intended
> recipient you should not disseminate,distribute,store,print, copy or
> deliver this message.Please notify the sender immediately by e-mail if
> you have received this e-mail by mistake and delete this e-mail from
> your system.E-mail transmission cannot be guaranteed to be secure or
> error-free as information could be
> intercepted,corrupted,lost,destroyed,arrive late or incomplete or
> contain viruses.The sender therefore does not accept liability for any
> errors or omissions in the contents of this message which arise as a
> result of e-mail transmission. If verification is required please
> request a hard-copy version.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org


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


Re: Default logging priorty/level of individual classes

Posted by Jacob Kjome <ho...@visi.com>.
First, you should use <level> instead of <priority>.  Second, the <root> is 
just a special kind of <logger>, the root one.  What you want to do is set 
a separate <logger> (of which, BTW, will inherit from <root> so it will use 
<root>'s appender).  Something like this...


<logger name="com.MyClass">
     <level value="info"/>
</logger>
<root>
     <level value="debug">
     <appender-ref ref="xmllayout"/>
</root>

Also, normally, I set the <root> logger to a higher threshold like "warn" 
and then set specific loggers to "info" or "debug".

Jake

At 04:54 PM 12/12/2003 -0700, you wrote:
>When my application starts I would like to default the logging
>priority/level of individual classes.  I know how to set the root using the
>following:
>
>...
>   <root>
>     <priority value = "debug" />
>     <appender-ref ref="xmllayout"/>
>   </root>
>...
>
>But I would like to set the default logging priority of com.myClass to INFO
>as follows...(but this doesn't work)
>...
>   <root>
>     <priority value = "debug" />
>     <priority class = "com.myClass" value ="info" />
>     <appender-ref ref="xmllayout"/>
>   </root>
>...
>
>Anyone know what I am doing incorrectly?
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org


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


Default logging priorty/level of individual classes

Posted by Scott Melcher <sm...@assistcorp.com>.
When my application starts I would like to default the logging
priority/level of individual classes.  I know how to set the root using the
following:

...
  <root>
    <priority value = "debug" />
    <appender-ref ref="xmllayout"/>
  </root>
...

But I would like to set the default logging priority of com.myClass to INFO
as follows...(but this doesn't work)
...
  <root>
    <priority value = "debug" />
    <priority class = "com.myClass" value ="info" />
    <appender-ref ref="xmllayout"/>
  </root>
...

Anyone know what I am doing incorrectly?



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


Re: log4j.xml configuration help

Posted by Adam Vainder <ad...@lexi.com>.
Since you're using the xml properties, set up 2 different loggers, and 
then attach filters to them.

Keep in mind that when attaching multiple filters to the same logger, 
that if the statement fails one filter, it will pass down to the next. A 
denial by a filter does not necessarily mean that the message is thrown 
away, the message just fails that filter and goes onto the next one 
(except in the case of DenyAllFilter). Which is why it's always safest 
to have a "DenyAllFilter" at the bottom of the list to catch the 
stragglers.

The filters you would need for this specific project are in the log4j 
package already.

e.g.

<log4j:configuration>
   <appender name="infoLogsFile" class="org.apache.log4j.FileAppender">
      <layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{MM-dd-
yyyy HH:mm:ss} %-5p %c - %m%n"/>
      </layout>
      <param name="file" value="info_messages.log"/>
      <filter class="org.apache.log4j.varia.LevelMatchFilter">
			<param name="LevelToMatch" value="INFO"/>
			<param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.DenyAllFilter"/>
  </appender>

  <appender name="otherLogsFile" class="org.apache.log4j.FileAppender">
      <layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{MM-dd-
yyyy HH:mm:ss} %-5p %c - %m%n"/>
      </layout>
      <param name="file" value="other_messages.log"/>
      <filter class="org.apache.log4j.varia.LevelMatchFilter">
			<param name="LevelToMatch" value="DEBUG"/>
			<param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.LevelRangeFilter">
			<param name="LevelMin" value="ERROR"/>
			<param name="LevelMax" value="FATAL"/>
			<param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.DenyAllFilter"/>
  </appender>

  <root>
		<priority value="ALL"/>
		<appender-ref ref="infoLogsFile"/>		
                <appender-ref ref="otherLogsFile"/>
  </root>
</log4j:configuration>
      

-----Original Message-----
From: <ra...@iflexsolutions.com>
To: <lo...@jakarta.apache.org>
Date: Wed, 10 Dec 2003 20:13:34 +0530
Subject: log4j.xml configuration help

> 
> 
> > Hi ,
> > 
> > I need help as i am new in using log4j.xml . 
> > 
> > My requirement is 
> > 
> > 1)When application uses INFO level , all the logs of the application
> should go into 1 log file ( say a.log)
> > 2)when application uses DEBUG, ERROR ,FATAL level all logs of the
> application should go into another log file ( say b.log)
> > 
> > 
> > Also log files path can be configurable and if file not exists can be
> created  . I am using log4j.xml not the lo4j.properties .
> > 
> > Pls suggest ,
> > 
> > ravindra 
> > 
> 
> 
> DISCLAIMER:
> This message contains privileged and confidential information and is
> intended only for the individual named.If you are not the intended
> recipient you should not disseminate,distribute,store,print, copy or
> deliver this message.Please notify the sender immediately by e-mail if
> you have received this e-mail by mistake and delete this e-mail from
> your system.E-mail transmission cannot be guaranteed to be secure or
> error-free as information could be
> intercepted,corrupted,lost,destroyed,arrive late or incomplete or
> contain viruses.The sender therefore does not accept liability for any
> errors or omissions in the contents of this message which arise as a
> result of e-mail transmission. If verification is required please
> request a hard-copy version.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org


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