R Dhaval
R Dhaval

Reputation: 546

How do slf4j Logger's debug/error/info methods internally work?

I tried to find the implementation of these methods but no luck. I want to know the implementation so that I can know how it handles String internally. I couldn't find anything anywhere. Possible that I was looking at wrong place. Please help with links/references. Thanks a lot.

Upvotes: 1

Views: 592

Answers (1)

glytching
glytching

Reputation: 47895

From the SLF4J docs:

The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and log4j. SLF4J allows the end-user to plug in the desired logging framework at deployment time

So, the Logger interface is declared in the SLF4J library and the implementation of that interface (i.e. the "debug/error/info methods") is declared in whichever underlying logging framework you have chosen.

Examples of the implementations (or at least the entrypoints into the implementations) for common logging libraries:

Note: the relationship between interface and implementation is straightforward for Logback (ch.qos.logback.classic.Logger implements org.slf4j.Logger) but for the other logging libraries there is typically an adapting layer which adapts the SLF4J interface to the implementation within each library. I have included links to some of those 'adapters' in the above list but a fuller set is available in the SLF4J GitHub repo: https://github.com/qos-ch/slf4j.

Upvotes: 2

Related Questions