Add logging abstraction with SLF4J backend#740
Open
mihaimitrea-db wants to merge 1 commit intomainfrom
Open
Conversation
This was referenced Mar 26, 2026
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.
🥞 Stacked PR
Use this link to review incremental changes.
Summary
Introduces a logging abstraction layer (
com.databricks.sdk.core.logging) that decouples the SDK's internal logging from any specific backend. SLF4J remains the default. This PR contains only the abstraction and the SLF4J backend; the JUL backend and the call-site migration follow in stacked PRs.Why
The SDK currently imports
org.slf4j.Loggerandorg.slf4j.LoggerFactorydirectly in every class that logs. This hard coupling means users who embed the SDK in environments where SLF4J is impractical (e.g. BI tools with constrained classpaths) have no way to switch to an alternative logging backend likejava.util.logging.We need an indirection layer that lets users swap the logging backend programmatically while keeping SLF4J as the zero-configuration default so that existing users don't have to change anything.
The design follows the pattern established by Netty's
InternalLoggerFactory: an abstractLoggerFactoryclass with concrete subclasses for each backend, asetDefaultmethod to override the backend, and a separateLoggerabstract class that serves as a clean extension point for custom implementations.What changed
Interface changes
Logger— new abstract class incom.databricks.sdk.core.logging. Defines the logging contract:debug,info,warn,error(each with plain-string and varargs overloads), andisDebugEnabled. Users extend this to build custom loggers.LoggerFactory— new abstract class. Static methodsgetLogger(Class<?>)andgetLogger(String)return loggers from the current default factory.setDefault(LoggerFactory)overrides the backend — must be called before creating any SDK client.Slf4jLoggerFactory— public concrete factory with a singletonINSTANCE. This is the default.Behavioral changes
None. SLF4J is the default backend and all logging calls pass through to
org.slf4j.Loggerexactly as before. Existing users see no difference.Internal changes
Slf4jLogger— package-private class that delegates all calls to anorg.slf4j.Logger. Fully qualifiesorg.slf4j.LoggerFactoryreferences to avoid collision with the SDK'sLoggerFactory.com.databricks.sdk.core.logging.How is this tested?
LoggerFactoryTest— verifies the default factory is SLF4J, thatsetDefault(null)is rejected, and thatgetLogger(String)works.Slf4jLoggerTest— verifiesSlf4jLogger.createreturns the correct type, and exercises all logging methods including varargs and trailing Throwable.