3

I was looking at reasons to prefer logback over log4j and came across this point :

logback-classic speaks SLF4J natively

Since the Logger class in logback-classic implements the SLF4J API natively, you incur zero overhead when invoking an SLF4J logger with logback-classic as the underlying implementation. Moreover, since logback-classic strongly encourages the use of SLF4J as its client API, if you need to switch to log4j or to j.u.l., you can do so by replacing one jar file with another. You will not need to touch your code logging via the SLF4J API. This can drastically reduce the work involved in switching logging frameworks.

Can some one please explain the above point ?

Community
  • 1
  • 1
Geek
  • 26,489
  • 43
  • 149
  • 227
  • Check these for better explanation - http://stackoverflow.com/a/932983/1268844 and http://stackoverflow.com/a/925098/1268844 – Anshu Oct 15 '12 at 06:22
  • Note that slf4j and logback is written by the same author, and logback is a fork of log4j. Hence, he would like people to use logback instead of log4j and this is one of the arguments. I wouldn't worry at this point. Backed features are much more important. – Thorbjørn Ravn Andersen Oct 15 '12 at 06:28

2 Answers2

3

If you use anything else als SLF4J implementation you need an additional bridge, which implments SLF4J interfaces by calling apropriate methods in the underlying implementation.

This will cause some overhead.

logback implements the interfaces directly so you don't need an additional bridge => no overhead.

Having said that, in most cases the overhead will be so small to be neglectable to the performance effects of the choosen logging library itself, so I wouldn't worry about it to much.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
0

The accepted answer is spot on. Just wanted to add this as a complementary bit of information.

If you look in logback-classic.jar in ch.qos.logback.classic.Logger you'll find:

public final class Logger implements org.slf4j.Logger ...

which is literally what the author is saying:

... the Logger class in logback-classic implements the SLF4J API natively ...

dev
  • 1,648
  • 16
  • 25