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

John O'Grady ogradyjd at gmail.com
Tue May 26 16:47:55 CEST 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/slf4j-dev/attachments/20090526/03d7d36d/attachment.htm>


More information about the slf4j-dev mailing list