AgentX
AgentX

Reputation: 1432

How is slf4j a facade?

I am trying to understand the details of slf4j. I am still not clear on how slf4j is considered as a Logging facade?

The intent of facade is to typically -

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

In case of slf4j it provides a generic Logger interface, but each binding project like log4j, logback etc. need to provide their concrete implementation.

So I understand the how the adapter pattern fits in but I am still not able to understand how Facade Pattern is being used.

Upvotes: 10

Views: 1293

Answers (2)

Ceki
Ceki

Reputation: 27490

SLF4J is not a facade in the strict sense. It only provides an API for the most common logging methods shared by most logging frameworks allowing the user to switch to a different API if need be with relative ease.

Upvotes: 3

Raffaele
Raffaele

Reputation: 20885

It's not a façade at the language level, it's a façade at the application level. When you write your application (or, even more important, a library!) you have to log statements somehow. If you tie your code to a specific log implementation (log4j, logback) it will be difficult to integrate it into another piece of code that uses another logging implementation, because you'll then have to configure things twice and possibly can't share the same output device.

This is especially important for library authors. So slf4j comes into play: you log to slf4j and then let use user of the library provide the actual logging machinary via the appropriate binding and the binding configuration.

Upvotes: 8

Related Questions