Edmondo
Edmondo

Reputation: 20090

Why slf4j Logger has no log method?

I am wondering why there is no

logger.log(level, ...) 

in slf4j. Is there a precise reason? When migrating from log4j to slf4j and using logback, this is causing me headache !

Upvotes: 4

Views: 919

Answers (2)

TheWhiteRabbit
TheWhiteRabbit

Reputation: 15768

slj4j is just a Wrapper around the actual Logger implementation, in order to provide flexibility to change the underlying implementation.

Having said that , instead .log(,) notation, slf4j uses logger.level() like - logger.debug() logger.info() etc

and that too based on the supported LEVEL defined in your underlying logger configuration for example logger.properties.

Upvotes: 2

hyde
hyde

Reputation: 62908

This is just speculation, but I think log(Level... type method is not in the interface for some combination of these reasons:

  • Keep number of methods in interface down
  • Avoid needing to define numeric log levels in the interface
  • Without numeric levels, just enum values, advantage of such method is not clear
  • Being as independent as possible from underlying log system's log levels by not having log level class at all
  • When dynamic log level would be desired by application, alternative might be Marker concept.

Upvotes: 0

Related Questions