java - SLF4J - how does it know which log type to use -
slf4j wrapper/facade class can use many different log types, such logback, log4j , etc. let's want use both logback , log4j , third java.util.logging. when write log this:
public class helloworld { public static void main(string[] args) { logger logger = loggerfactory.getlogger(helloworld.class); logger.info("hello world"); } }
how know logging framework using ? let's want use logback call, how know not using framework ?
as understood, slf4j interface , needs implementation. basically, slf4j call :
classloader.getsystemresources("org/slf4j/impl/staticloggerbinder.class");
it means classpath must contain such class qualified name.
every logging framework compatible slf4j defines such class.
- if dig code of
logback
, find class namedorg.slf4j.impl.staticloggerbinder
redirects logback's implementation - if dig code of log4j, there not such class there binding framework between
log4j
,slf4j
calledslf4j-log4j
define class namedorg.slf4j.impl.staticloggerbinder
redirects log4j's implementation.
so if want slf4j use particular framework, place accurate jar in classpath corresponding implementation of org.slf4j.impl.staticloggerbinder
found.
here big picture (source : http://www.slf4j.org/manual.html) :
Comments
Post a Comment