-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: make slf4j optional with fallback on JUL #1178
Conversation
484685e
to
c3493d3
Compare
Note I have only implemented the bare minimum interface necessary to allow this patch to drop into existing code. Additional log levels and log level methods can be implemented in the future if necessary. |
Hi, thanks for the PR. Can you check the failing CI tests ? |
looks like you may have forgotten to commit the new Logger class |
c3493d3
to
580932e
Compare
Classic! Re-pushed with the missing files. |
580932e
to
16d7fd5
Compare
I pushed two changes to address failures in a previous job run:
|
it shouldn't be, but it's been a while since i looked at it |
@gotson Originally the slf4j jar was added to those files during the addition of slf4j logging. Without the jar in CLASSPATH, the "amalgamation" job failed to run its |
Everything is green now. The job "test aarch64 ubuntu_latest jdk21" took a very long time, but I assume that is because it is running aarch64 tests in an emulator on an x86_64 job runner. |
we need to fix this, it should not be required. I pulled your PR code and tested locally, and the
I would say it's because you define this field in You can achieve the same behaviour by commenting the |
Not sure we can work around that though, maybe using reflection ? |
pom.xml
Outdated
@@ -415,6 +415,7 @@ | |||
<groupId>org.slf4j</groupId> | |||
<artifactId>slf4j-api</artifactId> | |||
<version>1.7.36</version> | |||
<scope>compile</scope> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compile
is already the default scope for a dependency with Maven. Adding it doesn't change anything : https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#dependency-scope
I guess if we want to make it optional it should not be automatically added transitively as a dependency and we should use the <optional>true</optional>
configuration ? https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not very familiar with Maven, but when we reference the SLF4J package, java needs to know the package, even if it is not included in the build, to compile the code.
i think we can leave it as is, and leave slf4j in the makefile to compile NativeDB.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The <optional>
configuration does not exclude the dependency for the sqlite-jdbc
build. It will still be added to the classpath when compiling.
The <optional>
configuration will only affect builds which depends on sqlite-jdbc
. The slf4j-api
will not be added as a transitive dependency. It should make the consumption easier like:
- one that don't want to use SLF4J would add:
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.46.1.0</version>
</dependency>
</dependencies>
instead of:
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.46.1.0</version>
</dependency>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependencies>
- one that want to use SLF4J would add:
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.46.1.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
</dependencies>
But if we want to use SLF4J the dependency should be already declared somewhere 😇.
It just triggers me because we say SLF4J is optional but it will still be added in the dependency graph if we don't exclude it explicitly. It may be not what people expect when using sqlite-jdbc
but this is not necessarily a big deal if this is documented 😇.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess optional would be better than compile then ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact this is an addition to the compile
scope, it would be:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
or just (which is equivalent):
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<optional>true</optional>
</dependency>
Because with Maven, when a scope is not set, it is compile
by default.
The other way to reproduce the same transitive mechanism behavior (not adding slf4j-api
automatically in the classpath when you depend on sqlite-jdbc
) would be to replace the compile
scope by provided
. But it does change a little the meaning because it would indicate that we really need slf4j-api
at runtime and that it should be provided by something else (an application server, etc): https://stackoverflow.com/questions/40393098/when-to-use-optional-dependencies-and-when-to-use-provided-scope
My 2 cents is to make the dependency <optional>
in sqlite-jdbc
which will not resolve slf4j-api
transitively when we depend on sqlite-jdbc
and let the consumer use this logging facade or not 😇.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2 cents is to make the dependency
<optional>
insqlite-jdbc
which will not resolveslf4j-api
transitively when we depend onsqlite-jdbc
and let the consumer use this logging facade or not 😇.
i am OK with that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2 cents is to make the dependency <optional>
I did not know this! I will make the change and re-push.
In order to avoid the hard dependency on slf4j, this patch abstracts the Logger interface and LoggerFactory factory to fall back on a java.util.logging-based implementation if slf4j is not present. Fixes xerial#1094
16d7fd5
to
c23bd02
Compare
I have updated the build to make slf4j optional, as @jcgay suggested. This should resolve the last few concerns about this PR, but let me know if anything else needs to change! |
@gotson Thank you! Looking forward to the release. |
Hi, |
@rmraya D'oh! Could you push a PR? I believe it should be From https://www.oracle.com/corporate/features/understanding-java-9-modules.html:
|
Marking as |
I'm not sure what the right option is then. Won't removing it altogether mean it cannot access those APIs at all at runtime? |
It still seems to me like |
OK, let me build from source and test. I'll post a PR when I have it working. |
Created new PR #1205 |
In order to avoid the hard dependency on slf4j, this patch abstracts the Logger interface and LoggerFactory factory to fall back on a java.util.logging-based implementation if slf4j is not present.
Fixes #1094