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 named org.slf4j.impl.staticloggerbinder redirects logback's implementation
  • if dig code of log4j, there not such class there binding framework between log4j , slf4j called slf4j-log4j define class named org.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) :

enter image description here


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -