Skip to content

Latest commit

 

History

History
118 lines (91 loc) · 5.29 KB

logging-fwk-comp.md

File metadata and controls

118 lines (91 loc) · 5.29 KB

Java Logging Frameworks Overview

Main frameworks

  • JDK Logging (JUL : java.util.logging)
  • Log4J 1.X
  • Log4J 2.X
  • Apache Commons-logging (JCL)
  • SLF4J

ℹ️ Logback is the reference implementation for SLF4J

ℹ️ Spring Framework historically use commons-logging

Loggers

Implementation classes

Framework Class name
JDK Logging java.util.logging.Logger
Log4J 1 org.apache.log4j.Logger
 Log4J 2 org.apache.logging.log4j.Logger
Commons-Logging org.apache.commons.logging.Log
SLF4J org.slf4j.Logger
Logback ch.qos.logback.classic.Logger

ℹ️ Note the Commons-Logging singularity

Obtain a Logger instance

Framework Package From name From class
JDK Logging java.util.logging Logger.getLogger("name") 🚫
Log4J 1 org.apache.log4j Logger.getLogger("name") Logger.getLogger(clazz)
 Log4J 2 org.apache.logging.log4j LogManager.getLogger("name") LogManager.getLogger(clazz)
Commons-Logging org.apache.commons.logging LogFactory.getLog("name") LogFactory.getLog(clazz)
SLF4J org.slf4j LoggerFactory.getLogger("name") LoggerFactory.getLogger(clazz)

Trace Methods

JDK Logging Log4J 1  Log4J 2 Commons-Logging SLF4J
finest() trace() trace() trace() trace()
finer() 🚫 🚫 🚫 🚫
 fine() debug() debug() debug() debug()
 config() 🚫 🚫 🚫 🚫
info() info() info() info() info()
warning() warn() warn() warn() warn()
🚫  error() error() error() error()
severe() fatal() fatal() fatal() 🚫
log() log() log() 🚫 🚫

ℹ️ Logback/SLF4J does not have a FATAL level

Levels

Implementation classes

Framework Class name
JDK Logging java.util.logging.Level
Log4J 1 org.apache.log4j.Level
 Log4J 2 org.apache.logging.log4j.Level
Commons-Logging 🚫
SLF4J org.slf4j.event.Level
Logback ch.qos.logback.classic.Level

Effectives levels

JDK Logging Log4J 1  Log4J 2 Commons-Logging SLF4J
ALL ALL ALL 🚫 🚫
FINEST TRACE TRACE TRACE TRACE
FINER 🚫 🚫 🚫 🚫
FINE DEBUG DEBUG DEBUG DEBUG
CONFIG 🚫 🚫 🚫 🚫
 INFO  INFO  INFO INFO  INFO
WARNING WARN WARN WARN WARN
🚫  ERROR ERROR ERROR ERROR
SEVERE FATAL  FATAL FATAL 🚫
OFF  OFF OFF 🚫 🚫

IsEnabled Methods

JDK Logging Log4J 1  Log4J 2 Commons-Logging SLF4J
isLoggable(Level) isEnabledFor(Priority) isEnabled(Level) 🚫 🚫
🚫 isTraceEnabled() isTraceEnabled() isTraceEnabled() isTraceEnabled()
🚫 isDebugEnabled() isDebugEnabled() isDebugEnabled() isDebugEnabled()
🚫 isInfoEnabled() isInfoEnabled() isInfoEnabled() isInfoEnabled()
🚫 🚫 isWarnEnabled() isWarnEnabled() isWarnEnabled()
🚫 🚫 isErrorEnabled() isErrorEnabled() isErrorEnabled()
🚫 🚫 isFatalEnabled() isFatalEnabled() 🚫

Context

JDK Logging Log4J 1  Log4J 2 Commons-Logging SLF4J
🚫  NDC ThreadContext 🚫  :no_entry_sign:
🚫  MDC ThreadContext 🚫  MDC

Links

Official pages

Tutorials