Skip to content

Implement a new module: bridge slf4j to rlib logger#71

Merged
JavaSaBr merged 3 commits into
developfrom
improve-logger-part-1
May 31, 2026
Merged

Implement a new module: bridge slf4j to rlib logger#71
JavaSaBr merged 3 commits into
developfrom
improve-logger-part-1

Conversation

@JavaSaBr
Copy link
Copy Markdown
Owner

@JavaSaBr JavaSaBr commented May 31, 2026

Overview

This branch improves the RLib logger API and adds TRACE level support across all logger implementations. It also introduces a new rlib-logger-slf4j-impl module 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 through LoggerManager.

Changes Summary

1. New LoggerLevel.TRACE

  • Added TRACE as the lowest-priority level to LoggerLevel enum, ordered before DEBUG
  • Disabled by default (enabled = false, printable = false) matching DEBUG defaults
  • All existing switch statements in Slf4jLogger and DefaultLogger updated to include TRACE

2. Extended Logger API

New abstract methods (must be implemented by all Logger implementations):

  • @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 is message + ": " + stackTrace in DefaultLogger, native SLF4J structured call in Slf4jLogger

New 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 to print(TRACE, message)
  • trace(String, Throwable) — delegates to print(TRACE, message, exception)

All new public methods include Javadoc with @param, @return, and @since 10.0.0.

3. Updated Implementations

  • DefaultLogger — implements name() and print(level, message, exception); removed unused VALUES constant
  • NullLogger — implements name() (returns "null") and no-op print(level, message, exception)
  • Slf4jLogger — implements name() (delegates to slf4j.Logger.getName()), print(level, message, exception) (native SLF4J call), and adds TRACE case to all existing switch statements

4. New Module: rlib-logger-slf4j-impl

A new SLF4J 2.x service provider module that routes SLF4J logging calls into the RLib logger pipeline.

SLF4J caller
     │  logger.info("msg")
     ▼
Slf4jLoggerImpl  (implements org.slf4j.Logger)
     │  delegates to
     ▼
javasabr.rlib.logger.api.Logger  (via LoggerManager.getLogger(name))
     │
     ▼
LoggerService / output

Components:

  • SLF4JServiceProviderImpl — implements SLF4JServiceProvider (SLF4J 2.x SPI); registers via META-INF/services/org.slf4j.spi.SLF4JServiceProvider; throws IllegalStateException if getLoggerFactory() is called before initialize()
  • Slf4jLoggerFactoryImplILoggerFactory that creates Slf4jLoggerImpl instances backed by LoggerManager.getLogger(name)
  • Slf4jLoggerImpl — full org.slf4j.Logger adapter; all 40+ SLF4J methods covered including Marker-accepting variants (markers are silently dropped — acceptable for a simple bridge); uses MessageFormatter from SLF4J helpers for parameterized message formatting

Registered via SLF4J 2.x service provider mechanism — adding this module to the classpath automatically routes all SLF4J calls through RLib without any code changes.

@JavaSaBr JavaSaBr self-assigned this May 31, 2026
Copilot AI review requested due to automatic review settings May 31, 2026 13:39
@github-actions
Copy link
Copy Markdown

Overall Project 56.28% -1.59% 🍏
Files changed 5.73%

File Coverage
LoggerLevel.java 100% 🍏
Logger.java 75.81% -3.7%
DefaultLogger.java 73.91% -17.39%
NullLogger.java 62.5% -37.5%
Slf4jLoggerFactoryImpl.java 0%
SLF4JServiceProviderImpl.java 0%
Slf4jLoggerImpl.java 0%
Slf4jLogger.java 0% -62.69%

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-impl and wired it into Gradle settings and JaCoCo aggregation.
  • Extended the logger API with Logger#name(), a TRACE level, and print(level, message, exception) (plus new convenience methods).
  • Implemented an SLF4J 2.x SLF4JServiceProvider + ILoggerFactory + org.slf4j.Logger adapter 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 thread rlib-logger-slf4j/src/main/java/javasabr/rlib/logger/slf4j/Slf4jLogger.java Outdated
Comment thread rlib-logger-impl/src/main/java/javasabr/rlib/logger/impl/DefaultLogger.java Outdated
Comment thread rlib-logger-api/src/main/java/javasabr/rlib/logger/api/impl/NullLogger.java Outdated
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);
@github-actions
Copy link
Copy Markdown

Overall Project 56.52% -1.56% 🍏
Files changed 20.41%

File Coverage
LoggerLevel.java 100% 🍏
Slf4jLoggerFactoryImpl.java 100% 🍏
DefaultLogger.java 97.39% 🍏
SLF4JServiceProviderImpl.java 78.95% -21.05% 🍏
Logger.java 76.73% -2.77%
NullLogger.java 62.5% -37.5%
Slf4jLoggerImpl.java 7.14% -92.86%
Slf4jLogger.java 0% -62.69%

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 21 comments.

@github-actions
Copy link
Copy Markdown

Overall Project 56.51% -1.61% 🍏
Files changed 23.21%

File Coverage
LoggerLevel.java 100% 🍏
Slf4jLoggerFactoryImpl.java 100% 🍏
DefaultLogger.java 97.39% 🍏
SLF4JServiceProviderImpl.java 78.95% -21.05% 🍏
Logger.java 75.81% -3.7%
NullLogger.java 62.5% -37.5%
Slf4jLoggerImpl.java 13.44% -86.56%
Slf4jLogger.java 0% -62.69%

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

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);
}
@JavaSaBr JavaSaBr merged commit 7e47dfd into develop May 31, 2026
7 checks passed
@JavaSaBr JavaSaBr deleted the improve-logger-part-1 branch May 31, 2026 14:55
@github-actions
Copy link
Copy Markdown

Overall Project 56.44% -1.61% 🍏
Files changed 23.21%

File Coverage
LoggerLevel.java 100% 🍏
Slf4jLoggerFactoryImpl.java 100% 🍏
DefaultLogger.java 97.39% 🍏
SLF4JServiceProviderImpl.java 78.95% -21.05% 🍏
Logger.java 75.81% -3.7%
NullLogger.java 62.5% -37.5%
Slf4jLoggerImpl.java 13.44% -86.56%
Slf4jLogger.java 0% -62.69%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants