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 "Edward Q. Bridges" <eb...@teachscape.com> on 2002/03/20 21:56:41 UTC

selecting appender based on level

is it possible to use a different appender depending on the level?

in particular, we would like to log to syslog instead of to a log file when a message is 
sent to a Category with level "ERROR".  messages at levels "INFO" "WARN" etc. would 
go to a file.

how would we be able to configure this?

thanks!
--e--



--
Edward Q. Bridges
http://www.teachscape.com



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: selecting appender based on level

Posted by Keith Schomburg <ks...@cisco.com>.
Below is an example that logs INFO messages to the console
and WARN messages to a file.  You need to basically define
a filter in your configuration file for your appender.

Keith

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

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

  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-5p %c{2} - %m\n"/>
    </layout>
    <filter class="org.apache.log4j.varia.PriorityMatchFilter">
      <param name="PriorityToMatch" value="WARN" />
      <param name="AcceptOnMatch" value="true" />
    </filter>
  </appender>

  <appender name="FILE" class="org.apache.log4j.FileAppender">
    <param name="Append" value="false" />
    <param name="File"   value="temp.log" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-5p %c{2} - %m\n"/>
    </layout>
    <filter class="org.apache.log4j.varia.PriorityMatchFilter">
      <param name="PriorityToMatch" value="INFO" />
      <param name="AcceptOnMatch" value="true" />
    </filter>
  </appender>

  <root>
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="FILE" />
  </root>

</log4j:configuration>
----------------------------------------------------------------------------
-----------


> -----Original Message-----
> From: Edward Q. Bridges [mailto:ebridges@teachscape.com]
> Sent: Wednesday, March 20, 2002 3:57 PM
> To: log4j-user@jakarta.apache.org
> Subject: selecting appender based on level
>
>
> is it possible to use a different appender depending on the level?
>
> in particular, we would like to log to syslog instead of to a log
> file when a message is
> sent to a Category with level "ERROR".  messages at levels "INFO"
> "WARN" etc. would
> go to a file.
>
> how would we be able to configure this?
>
> thanks!
> --e--
>
>
>
> --
> Edward Q. Bridges
> http://www.teachscape.com
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>