NOPLogger does not do anything and consequently cannot be location
aware. The code log(String FQCN, Priority p, Object msg, Throwable t)
method throws an exception because the caller expects location aware
logging but the actual logger implementation is not capable of
delivering "location awareness".  One easy solution to this problem is
to modify the said log method as follows:

  public void log(String FQCN, Priority p, Object msg, Throwable t) {
    int levelInt = priorityToLevelInt(p);
    differentiatedLog(null, FQCN, levelInt, msg, t);
  }


I'll happily make the change provided you enter a bug report asking
for this modification.

By the way, your scenario does not makes sense to me. If I understand
correctly, you are using logback-classic as your logging
framework. You have a logback appender doing logging. If that appender
logs during its own initialization or obtains a logger, since SLF4J
will not be yet initialized the returned logger will be of type
NOPLogger. But that will not exercise code found in log4j-over-slf4j
unless the logback-class appender you are using depends on some other
library which uses log4j. Is that the case?

On 22/02/2010 4:12 PM, Seth Call wrote:
Hi Ceki,

The method in question is this:

public void log(String FQCN, Priority p, Object msg, Throwable t) {
int levelInt = priorityToLevelInt(p);
if (locationAwareLogger != null) {
locationAwareLogger.log(null, FQCN, levelInt, convertToString(msg), t);
} else {
throw new UnsupportedOperationException("The logger [" + slf4jLogger
+ "] does not seem to be location aware.");
}
}

You are right: I only saw this when the logger was the NOPLogger. I saw
the UnsupportedOperationException shown in that method was thrown.

What I'm suggesting is that the NOPLogger should implement
LocationAwareLogger, since I don't see any value in having the NOPLogger
stop a log from happening...

Thanks,
Seth

On 2/22/10 12:45 AM, Ceki Gulcu wrote:
Hello Seth,


Reading the code of the Category class in log4j-over-slf4j, it appears
that both loggers of type org.slf4j.Logger *and* LocationAwareLogger
are supported. Category class in log4j-over-slf4j should throw an
exception if the slf4j logger it gets is of type NOPLogger. Can you
show the exception you are observing?

Cheers,

On 22.02.2010 01:57, ownedthx wrote:

Hi all,

I'm using a logback appender which logs during startup, causing a
NOPLogger
to be created while the underlying library initializes.

In this specific scenario, I'm coercing a 3rd-party library out of
direct
log4j usage by using the log4j-over-slf4j bridge. However, the
Category.java implementation in the bridge will throw an exception if
the
underlying logger (in this case, NOPLogger) does not implement the
LocationAwareLogger interface.

This seems wrong to me--seems to me the NOPLogger should implement
LocationAwareLogger, and NOP the log statement specific to that, just
like
it does with all the other various log overloads it implements,
instead of
causing the appender to fail to start.

Any thoughts on this?

By the way, I did stop the error by doing just what was recommended
here...

Thanks,
Seth



_______________________________________________
slf4j-user mailing list
slf4j-user@qos.ch
http://qos.ch/mailman/listinfo/slf4j-user

_______________________________________________
slf4j-user mailing list
slf4j-user@qos.ch
http://qos.ch/mailman/listinfo/slf4j-user

_______________________________________________
slf4j-user mailing list
slf4j-user@qos.ch
http://qos.ch/mailman/listinfo/slf4j-user

Reply via email to