[slf4j-dev] Request for a log message processing hook.

Ceki Gulcu ceki at qos.ch
Tue May 26 17:19:24 CEST 2009


Hello John,

Thank you for the praise.

SLF4J offers very little in terms of functionality beyond the
abstraction of logging frameworks.  Have you considered extending the
underlying logging framework, e.g. log4j or logback, instead? I
believe that logback has the feature you are looking for already
built-in. See http://logback.qos.ch/manual/filters.html#TurboFilter
for more details.


John O'Grady wrote:
> Hello devs - I love your product, and I'm trying to use it in a special 
> logging system I'm developing as an open source project.  One of the 
> things I need for this to work is the ability to intercept messages 
> being logged by the slf4j framework, ostensibly right after the message 
> has been "processed" by the inner slf4j workings and before it is sent 
> to the underlying logging system.
> 
> As an example, take this code from org.slf4j.impl.Log4jLoggerAdapter.java:
> 
>   public void debug(String format, Object[] argArray) {
> 
>     if (logger.isDebugEnabled()) {
>       String msgStr = MessageFormatter.arrayFormat(format, argArray);
> 
>       logger.log(FQCN, Level.DEBUG, msgStr, null);
>     }
> 
>   }
> 
> 
> What I'm looking for would be something like this:
> 
>   public void debug(String format, Object[] argArray) {
> 
>     sendMsgToListeners(FQCN, Level.DEBUG, format, argArray, logger.isDebugEnabled());
> 
>     if(logger.isDebugEnabled()) {
>       String msgStr = MessageFormatter.arrayFormat(format, argArray);
> 
>       logger.log(FQCN, Level.DEBUG, msgStr, null);
>     }
> 
>   }
> 
>   private void sendMsgToListeners(String fqcn, String logLvl, String format, Object[] argArray, boolean isLoggable) {
>     for(LogListener listener : this.logListeners) {
> 
>       listener.fire(fqcn, logLvl, format, argArray, isLoggable);
>     }
>   }
> 
> 
> That way, other systems could piggyback off of slf4j and make their own 
> decisions about whether or not they want to process the incoming log 
> message based on the underlying log setup (logger.isDebugEnabled()) and 
> their own criteria. Hooks like this would make it easy to add quite a 
> few other abilities to the framework as well.
> 
> So have any of the devs discussed this kind of thing before - do any of 
> you think it's possible?
> 
> 
> John O'Grady
> GSI Commerce
> Facets Technologies
> 

-- 
Ceki Gülcü
The complete log4j manual: http://www.qos.ch/log4j/



More information about the slf4j-dev mailing list