Reputation: 2931
We have extended SLF4J's Logger
API and created AppLogger
interface. We have to do this for certain need which I cannot disclose here. Now, we want to use this extended logger with LogBack framework. I am not able to find any mechanism how to make it work. Direct usage is throwing ClassCastException
(this is obvious because it is expecting a class with name Logger
and getting AppLogger
).
I am able to make this extended interface work with Log4J 1.x
and Log4J 2.x
by writing a bridge implementation and providing custom StaticBinder
classes. For LogBack, this bridge class (StaticBinder
) is part of logback-classic
JAR file, so I am not sure how to write my own binder and bridge LogBack.
The AppLogger
interface looks like:
public interface AppLogger extends org.slf4j.Logger {
public void myOwnMethod(String message, Object... args);
}
Appreciate if anyone provide any idea.
Upvotes: 1
Views: 1234
Reputation: 27500
Up to version 1.7.15 SLF4J binding mechanism used to be very very very simple. After version 1.7.15, with the introduction of event replay the mechanism got a little more complicated but the core binding idea remains simple. Moreover, for those who can't be bothered, any support for event replay can be safely omitted.
For examples of slf4j bindings, see code in slf4j-nop or slf4j-simple modules.
However, from what I gather, you wish use an extended Logger API in which case you should look into LoggerWrapper
, XLogger
and XLoggerFactory
classes in the slf4j-ext module. You should be able to easily emulate the same procedure for your AppLogger
interface.
Upvotes: 3