At 09:16 11.05.2001 +0200, Marco Brandizi wrote:
>Hello,
>
>I'm an happy user of Log4J. I didn't understand if in new 1.6b version
>is avaible a "Priority Appender". I mean: an appender able to dispatch
>received messages to several destinations, one per each priority level. 

You can attach multiple appenders to a category. In addition, filters can be added to 
appenders. 

>I already have developed classes to do that (one generic and one child,
>specific for files), which you find attached to this message, but still
>I have to develop the XML configuration part, which is very important
>for the context where I use them. If someone already has something
>alike, would be welcome ;-)

Assuming you errors to go error.log and debug output to go debug.log, you could add 
two file appenders to the root category and attach a filter allowing only errors in 
the first and only debugs in the second. See 
org.apache.log4j.varia.PriorityMatchFilter and 
org.apache.log4j.varia.PriorityRangeFilter.


>Please, answer me privately too, not only in the mailing list, otherwise
>I could forget it... ;-)
>
>Greetings

I have a few comments on your code. They are prefixed by \\\.


>-----------------------------------------------------------
>PriorityAppender.java ------------------------------
>
>import org.log4j.*;
>import org.log4j.spi.*;
>import java.util.HashMap;
>import java.util.Iterator;
>
>
>/**
> * (2000) Marco Brandizi
> *
> * This code is free and to be intended as covered by the principles
>stated in
> * GNU LGPL
> *
> * An appender used for associate an appender to each priority type, in
>the same
> * logging category, i.e.: You may send messages of cat C to
>C-errors.log
> * C-warn.logs, etc
> *
> */

\\\ We can only accept contributions that are under the Apache 
\\\ Software License. LGPL is a no-no.


>public class PriorityAppender implements Appender {

\\\ You should have implemented the AppanderAttachable interface. 
\\\ See for example the AsyncAppender.

>  private HashMap appenders = new HashMap();

\\\ HashMap was introduced in JDK 1.2. Log4j requires JDK 1.1 compatibility.

>  private String name = "PriorityAppender";
>
>  /** Adds an appender, associated to a priority, if p already had one,
>      throws it away */
>  public void addAppender ( Priority p, Appender a )
>  {
>
>    Appender old = (Appender) appenders.get ( p );
>
>    if ( old == a )
>      // Hey, it's the same!
>      return;
>    else if (old != null )
>      // Release the old one
>      old.close();
>    else
>      // Append new
>      appenders.put (p, a);
>  }
>
>  /** null if p isn't correct */
>  public Appender getAppender ( Priority p )
>  {
>    return (Appender) appenders.get (p);
>  }
>
>  /** Appenders are removed at end */
>  protected void removeAppenders ()
>  {
>    Iterator iA = appenders.values().iterator();
>    Appender a;
>    while ( iA.hasNext() )
>        ((Appender)iA.next()).close();
>    appenders = null;
>  }
>
>
>  /** Does nothing, I don't need them here... */
>  public void addFilter(Filter newFilter) {
>  }
>
>  /** Does nothing, I don't need them here... */
>  public void clearFilters() {
>  }
>
>  public void close() {
>    removeAppenders();
>  }
>
>  /** Switch the priority and forward to the proper appender */
>  public void doAppend(LoggingEvent event) {
>    Appender a = getAppender ( event.priority );
>    a.doAppend(event);
>  }
>
>  /** Default is "PriorityAppender" */
>  public String getName() {
>    return name;
>  }
>
>  /** Does nothing, I don't need them here... */
>  public void setErrorHandler(ErrorHandler errorHandler) {
>  }
>
>  /** Does nothing, I don't need them here... */
>  public void setLayout(Layout layout) {
>  }
>
>  public void setName(String name) {
>    this.name = name;
>  }
>
>  /** FALSE! */
>  public boolean requiresLayout() {
>    return false;
>  }
>
>}

\\\ That's it.

Regards, Ceki

--
Ceki Gülcü


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to