Implement a new module: bridge slf4j to rlib logger#71
Merged
Conversation
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new rlib-logger-slf4j-impl module to provide an SLF4J 2.x service provider that routes SLF4J logging into RLib’s Logger/LoggerManager, while also extending the RLib logging API to better support SLF4J-style usage (logger naming, TRACE level, and message+exception printing).
Changes:
- Added
:rlib-logger-slf4j-impland wired it into Gradle settings and JaCoCo aggregation. - Extended the logger API with
Logger#name(), aTRACElevel, andprint(level, message, exception)(plus new convenience methods). - Implemented an SLF4J 2.x
SLF4JServiceProvider+ILoggerFactory+org.slf4j.Loggeradapter backed by RLib’s logger.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| test-coverage/build.gradle | Includes the new module in JaCoCo aggregation. |
| settings.gradle | Registers the new :rlib-logger-slf4j-impl Gradle module. |
| rlib-logger-slf4j/src/main/java/javasabr/rlib/logger/slf4j/Slf4jLogger.java | Updates SLF4J→RLib adapter to support TRACE, name(), and message+exception printing. |
| rlib-logger-slf4j-impl/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider | Registers the SLF4J service provider for ServiceLoader discovery. |
| rlib-logger-slf4j-impl/src/main/java/javasabr/rlib/logger/slf4j/impl/SLF4JServiceProviderImpl.java | Implements SLF4J 2.x provider bootstrap (factory/marker/MDC wiring). |
| rlib-logger-slf4j-impl/src/main/java/javasabr/rlib/logger/slf4j/impl/Slf4jLoggerImpl.java | Implements SLF4J Logger by delegating to RLib Logger. |
| rlib-logger-slf4j-impl/src/main/java/javasabr/rlib/logger/slf4j/impl/Slf4jLoggerFactoryImpl.java | Provides SLF4J ILoggerFactory backed by LoggerManager. |
| rlib-logger-slf4j-impl/src/main/java/javasabr/rlib/logger/slf4j/impl/package-info.java | Enables JSpecify @NullMarked for the impl package. |
| rlib-logger-slf4j-impl/build.gradle | Adds module build/publishing config and SLF4J deps. |
| rlib-logger-impl/src/main/java/javasabr/rlib/logger/impl/DefaultLogger.java | Implements new Logger API methods (name + print with message+exception). |
| rlib-logger-api/src/test/java/javasabr/rlib/logger/api/LoggerTest.java | Extends tests to cover new TRACE convenience methods and updated Logger contract. |
| rlib-logger-api/src/main/java/javasabr/rlib/logger/api/LoggerLevel.java | Adds TRACE to the log level enum. |
| rlib-logger-api/src/main/java/javasabr/rlib/logger/api/Logger.java | Adds name(), TRACE convenience methods, and message+exception printing API. |
| rlib-logger-api/src/main/java/javasabr/rlib/logger/api/impl/NullLogger.java | Updates NullLogger to satisfy new Logger interface methods. |
Comment on lines
18
to
23
| public enum LoggerLevel { | ||
| INFO("INFO", " ", true, true), | ||
| TRACE("TRACE", " ", false, false), | ||
| DEBUG("DEBUG", " ", false, false), | ||
| INFO("INFO", " ", true, true), | ||
| WARNING("WARN", " ", true, true), | ||
| ERROR("ERROR", " ", true, true); |
|
|
Comment on lines
+14
to
+16
| public Logger getLogger(String name) { | ||
| return loggers | ||
| .computeIfAbsent(name, requested -> new Slf4jLoggerImpl(LoggerManager.getLogger(requested))); |
Comment on lines
+248
to
+250
| default void debug(@NonNull String message, @NonNull Throwable exception) { | ||
| print(LoggerLevel.DEBUG, message, exception); | ||
| } |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This branch improves the RLib logger API and adds
TRACElevel support across all logger implementations. It also introduces a newrlib-logger-slf4j-implmodule that acts as an SLF4J 2.x service provider, bridging SLF4J logging calls into the RLib logger pipeline — allowing libraries that log via SLF4J to route output throughLoggerManager.Changes Summary
1. New
LoggerLevel.TRACETRACEas the lowest-priority level toLoggerLevelenum, ordered beforeDEBUGenabled = false,printable = false) matchingDEBUGdefaultsSlf4jLoggerandDefaultLoggerupdated to includeTRACE2. Extended
LoggerAPINew abstract methods (must be implemented by all
Loggerimplementations):@NonNull String name()— returns the logger's name (used by SLF4J bridge and other tooling)void print(LoggerLevel, String, Throwable)— low-level print with both a message and an exception; output ismessage + ": " + stackTraceinDefaultLogger, native SLF4J structured call inSlf4jLoggerNew default convenience overloads (message + exception) for all levels:
trace(String, Throwable),debug(String, Throwable),info(String, Throwable)warn(String, Throwable),error(String, Throwable)New trace logging defaults:
trace(String)— delegates toprint(TRACE, message)trace(String, Throwable)— delegates toprint(TRACE, message, exception)All new public methods include Javadoc with
@param,@return, and@since 10.0.0.3. Updated Implementations
DefaultLogger— implementsname()andprint(level, message, exception); removed unusedVALUESconstantNullLogger— implementsname()(returns"null") and no-opprint(level, message, exception)Slf4jLogger— implementsname()(delegates toslf4j.Logger.getName()),print(level, message, exception)(native SLF4J call), and addsTRACEcase to all existing switch statements4. New Module:
rlib-logger-slf4j-implA new SLF4J 2.x service provider module that routes SLF4J logging calls into the RLib logger pipeline.
Components:
SLF4JServiceProviderImpl— implementsSLF4JServiceProvider(SLF4J 2.x SPI); registers viaMETA-INF/services/org.slf4j.spi.SLF4JServiceProvider; throwsIllegalStateExceptionifgetLoggerFactory()is called beforeinitialize()Slf4jLoggerFactoryImpl—ILoggerFactorythat createsSlf4jLoggerImplinstances backed byLoggerManager.getLogger(name)Slf4jLoggerImpl— fullorg.slf4j.Loggeradapter; all 40+ SLF4J methods covered includingMarker-accepting variants (markers are silently dropped — acceptable for a simple bridge); usesMessageFormatterfrom SLF4J helpers for parameterized message formattingRegistered via SLF4J 2.x service provider mechanism — adding this module to the classpath automatically routes all SLF4J calls through RLib without any code changes.