Skip to main content
Jump to: navigation, search

EclipseLink/Development/296391

EclipseLink Logger bridge over SLF4J

Document History

Date Author Version Description & Notes
20150731 Tomas Kraus 1.0 Initial design draft

Problem Statement

EclipseLink is missing Simple Logging Facade for Java (SLF4J) API support. SLF4J logging frameworks became quite popular and Bug# 296391 got many votes.

Design

SLF4J logger bridge is implemented as org.eclipse.persistence.logging.SLF4JLogger class. SLF4J logger bridge implements SessionLog interface to support EclipseLink logging API. Most of the code is already available in AbstractSessionLog so this class is extended to add bridge from SessionLog methods to SLF4J API. SLF4J logger class overwrites following methods:

public void log(SessionLogEntry logEntry) 
Calls SLF4J API logging method corresponding to message log level.
public int getLevel() 
Retrieve current log level for default EclipseLink logging category.
public int getLevel(String categoryName) 
Retrieve current log level for specified EclipseLink logging category.
public void setLevel(int level) 
Set the log level for default EclipseLink logging category.
public void setLevel(int level, String categoryName) 
Set the log level for specified EclipseLink logging category.
public boolean shouldLog(int level) 
Check if a message of the given log level would actually be logged under logging level for default logging category.
public boolean shouldLog(int level, String categoryName) 
Check if a message of the given log level would actually be logged under logging level for specified logging category.

Unfortunately SLF4J API does not allow to set logging level to the SLF4J backend so log levels are stored in SLF4JLogger instance only. Current logging level of the SLF4JLogger instance controls if SLF4J backend is called for provided SessionLogEntry instance or not. SLF4J backend logging level configuration is independent on setLevel methods and should be configutred to pass required logging levels.

EclipseLink and SLF4J log levels are mapped according to following table:

EclipseLink SLF4J
OFF N/A
SEVERE ERROR
WARNING WARN
INFO INFO
CONFIG
FINE DEBUG
FINER
FINEST TRACE
ALL

EclipseLink logging categories are mapped to SLF4J API name spaces as eclipselink.logging.<category_name>, e.g. eclipselink.logging.sql. This mapping is implemented in static Logger getLogger(LogCategory category) method of SLF4JLogger class.

Back to the top