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.<br>
<br>As an example, take this code from org.slf4j.impl.Log4jLoggerAdapter.java:<br><font size="2"><br style="font-family: courier new,monospace;"></font><pre><font size="2"><span style="font-family: courier new,monospace;"> public void debug(String format, Object[] argArray) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if (logger.isDebugEnabled()) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> String msgStr = MessageFormatter.arrayFormat(format, argArray);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> logger.log(FQCN, Level.DEBUG, msgStr, null);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span></font><br></pre><br>What I'm looking for would be something like this:<br><br><pre><font size="2"><span style="font-family: courier new,monospace;"> public void debug(String format, Object[] argArray) {<br>
</span></font><font size="2"><span style="font-family: courier new,monospace;">sendMsgToListeners(FQCN, Level.DEBUG, </span></font><font size="2"><span style="font-family: courier new,monospace;">format, argArray</span></font><font size="2"><span style="font-family: courier new,monospace;">, </span></font><font size="2"><span style="font-family: courier new,monospace;">logger.isDebugEnabled()</span></font><font size="2"><span style="font-family: courier new,monospace;">);</span></font><br>
<font size="2"><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> if(logger.isDebugEnabled()) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> String msgStr = MessageFormatter.arrayFormat(format, argArray);<br style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;"> logger.log(FQCN, Level.DEBUG, msgStr, null);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }<br><br> private void sendMsgToListeners(String fqcn, String logLvl, String format, Object[] argArray, boolean isLoggable) {<br> for(LogListener listener : this.logListeners) {<br>
listener.fire(fqcn, logLvl, format, argArray, isLoggable);<br> }<br> }<br></span></font></pre>
<br><font size="2"><span style="font-family: arial,helvetica,sans-serif;">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 (</span></font><font style="font-family: arial,helvetica,sans-serif;" size="2">logger.isDebugEnabled()) </font><font size="2"><span style="font-family: arial,helvetica,sans-serif;">and their own criteria. Hooks like this would make it easy to add quite a few other abilities to the framework as well.<br>
<br>So have any of the devs discussed this kind of thing before - do any of you think it's possible?<br><br><br>John O'Grady<br></span></font><font size="2"><span style="font-family: arial,helvetica,sans-serif;">GSI Commerce</span></font><br>
<font size="2"><span style="font-family: arial,helvetica,sans-serif;">Facets Technologies<br><br></span></font><br><br><br>