logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Logger vs. Appender
Date Mon, 08 May 2006 16:23:54 GMT

On May 8, 2006, at 1:33 AM, David Hosier wrote:

...
>
> Anyway...thanks again for the reply, looking forward to hearing other
> people's thoughts.
>

I'd suggest creating a static helper class that generates a message  
object and then calls logger methods.  The message object's toString 
() should return a string that would be appropriate when the logging  
request is handled by stock appenders like ConsoleAppender and  
FileAppender, however your custom appender can get the message object  
and get at the parts.  The fragments could look something like:

public class FooBarLogger {
     private FooBarLogger() {}
     public static void info(final Logger logger, final Account  
account, final Transaction transaction) {
         if (logger.isInfoEnabled()) {
              logger.info(new FooBarMessage(account, transaction));
         }
     }
}

public class FooBarMessage {
     private final Account account;
     private final Transaction transaction;
     public FooBarMessage(final Account account, final Transaction  
transaction) {
         this.account = account;
         this.transaction = transaction;
   }
   public String toString() {
       return account.toString() + transaction.toString();
   }
   public Transaction getTransaction() {
       return transaction;
   }
   public Account getAccount() {
      return account;
   }
}

public class FooBarAppender extends AppenderSkeleton {
     ...
     public void doAppend(final LoggingEvent event) {
         if (event.getMessage() instanceof FooBarMessage) {
              ...
         } else {
             ...
         }
     }
}




---------------------------------------------------------------------
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