[slf4j-dev] [Bug 44] Repeat of bug 23: Log origination function doesn't show up correctly with slf4j-log4j

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Tue Apr 3 14:40:58 CEST 2007


show_bug.cgi?id=44


listid at qos.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from listid at qos.ch  2007-04-03 14:40 -------
Hi Toli,

Looking at the source code of SLF4JLog [1,2], I am pretty confident
that the issue is not a *bug* in SLF4J, be it in its log4j adapter or
in jcl104-over-slf4j. As such, I am going to close this report as
invalid. If you wish to continue this discussion, I encourage you do so 
on user at slf4j.

Here is a possible solution to the issue you are facing. In the
quickfix.SLF4JLog class you are writing an adapter for Quickfix's log
interface using SLF4J. This is similar to the task handled by
jcl104-over-slf4j, at least when viewed abstractly. Moreover, the
approach adopted in jcl104-over-slf4j should be applicable.

Given that you do not know the logging implementation returned by
SLF4J, you cannot be sure that it will implement the
LocationAwareLogger interface. However, if the returned implementation
does implement LocationAwareLogger, you can call the following method:

 log(Marker marker, String fqcn, int level, String message, Throwable t) 

It is designed to overcome the loss of caller information observed
when logging through intermediaries. More precisely, you should modify
the log method in quickfix.SLF4JLog, from:


 private void log(Logger log, String text) {
   if (log.isInfoEnabled()) {
     log.info(logPrefix != null ? (logPrefix + text) : text);
   }
 }

to:

 private void log(Logger log, String text) {
   if (log.isInfoEnabled()) {
     if(log instanceof LocationAwareLogger) {
       LocationAwareLogger la = (LocationAwareLogger) log;
       la.log(null, SLF4JLog.class.getName(), LocationAwareLogger.INFO_INT,
              logPrefix != null ? (logPrefix + text) : text,
              null);
     } else {
       log.info(logPrefix != null ? (logPrefix + text) : text);
     }
   }
 }


In the above, I tried to constrain all changes into a single
method. Other more optimized variants are possible, even encouraged.

HTH,

[1] http://tinyurl.com/2etbj9
[2]
http://quickfixj.svn.sourceforge.net/viewvc/quickfixj/trunk/core/src/main/java/quickfix/SLF4JLog.java?revision=585&view=markup


-- 
Configure bugmail: userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the slf4j-dev mailing list