-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
Use the SLF4J logging API directly #13285
Conversation
Motivation: SLF4J has been the defacto standard logging API in the Java world for a while. Normally we don't like to expose vendor APIs, but I think we can make an exception in this case. By using it directly, we can get rid of our own logging API code that isn't inherently relevant to what Netty does. It also means we can more easily make use of more advanced logging features like MDC and LoggingEventBuilders. Modification: Remove our internal logging API and use SLF4J everywhere. Switch back from log4j to using logback for our testing. Result: Less code to maintain, and everyone gets to use the same logging API.
Draft because the Graal meta-data needs to be updated as well. |
Thank you for this PR! I love this change. |
codec-http2/src/test/java/io/netty5/handler/codec/http2/Http2StreamChannelBootstrapTest.java
Show resolved
Hide resolved
example/src/main/java/io/netty5/example/factorial/FactorialServer.java
Outdated
Show resolved
Hide resolved
@@ -81,7 +80,7 @@ public class EpollReuseAddrTest { | |||
BUGFIX = 0; | |||
} | |||
} else { | |||
LOGGER.log(InternalLogLevel.INFO, "Unable to parse kernel version: " + kernelVersion); | |||
LOGGER.info("Unable to parse kernel version: {}", kernelVersion); |
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.
why do you sometimes use atInfo()...
and sometimes the above pattern ? Imho we should be consistent. I suspect the pattern above creates less GC as there is no extra builder created.
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 atLevel()
method is the only way to dynamically specify the log level in their 2.0 API. There were two places where I used atWarn()
, and I'll fix those.
transport/src/main/java/io/netty5/channel/DefaultChannelHandlerContext.java
Outdated
Show resolved
Hide resolved
This is not the same as regenerating the reflection configuration, which needs to happen, but let's see what the build says about it first.
Hmm… the h2spec testsuite runs inside the Maven process itself, and Maven depends on slf4j 1.7, with no apparent way override this in the plugin classloader. That's why that module fails with "no such method error". |
…he correct classpath The h2spec-maven-plugin runs the server with the Maven-internal classloader as the parent classloader, which means we cannot override the slf4j version that Maven otherwise uses. By dropping the parent classloader, and only relying on our own URLClassLoader, we get the correct test-classpath that we want.
Managed to work around this with a bit of class loader magic. |
|
||
/** | ||
* Maps the regular {@link LogLevel}s with the {@link InternalLogLevel} ones. | ||
* Logging level for configuring {@link LoggingHandler}. | ||
*/ | ||
public enum LogLevel { |
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.
But shouldn't we make it package-private and hide it from the public API?
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.
It was the whole point to make this public and so "hide" slf4j from the public API .
@@ -46,38 +46,38 @@ public void queryWritten(InetSocketAddress dnsServerAddress, Future<Void> future | |||
@Override | |||
public void queryCancelled(int queriesRemaining) { | |||
if (dnsServerAddress != null) { | |||
logger.log(level, "from {} : {} cancelled with {} queries remaining", dnsServerAddress, question, | |||
logger.atLevel(level).log("from {} : {} cancelled with {} queries remaining", dnsServerAddress, question, |
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.
Could extract logger.atLevel(level)
into a member field so we don't have to call it every time. I guess this could be potentially creating a new instance for each log message.
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 API is meant to build a new LogEvent every time. Otherwise you'll carry over data from previous log messages. For instance, the arguments (dnsServerAddress, etc.) given here will accumulate.
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.
If we cache the builder we will also not be told about runtime log level changes.
testsuite-http2/src/main/java/io/netty5/testsuite/http2/Http2Server.java
Show resolved
Hide resolved
Hmm? Why hide SLF4J from the public API? We pull it in as a non-shaded
dependency and it's already the de facto standard logging facade in Java
ecosystem.
|
imho it is far better to just have it as an internal dependency then leaking it to the public api. |
@normanmaurer @trustin I've addressed your comments. Please take a look. |
@chrisvest @normanmaurer There is a bit of inconsistency now in the API The Are you going at some point to expose slf4j everywhere and remove |
Adaptations made for the Netty5 SLF4J netty/netty#13285 PR. socks-proxy and codec-multipart netty contrib projects have also been updated, because io.netty5.util.internal.logging.InternalLoggerFactory is not supported anymore.
@violetagg Oops, looks like we didn't revert all the usages. I'll make a PR. |
Motivation: The is _a lot_ going on in netty#13285, and we missed that we exposed the SLF4J level in a couple of places. We also _somehow_ missed that we broke compilation of EchoIT in the buffer-memory-segment module. Modification: Replace the remaining places that exposed SLF4J Level to the public API, and fix the compilation. Result: No more left-overs to clean up after netty#13285
This should fix it: #13304 |
Motivation: The is _a lot_ going on in #13285, and we missed that we exposed the SLF4J level in a couple of places. We also _somehow_ missed that we broke compilation of EchoIT in the buffer-memory-segment module. Modification: Replace the remaining places that exposed SLF4J Level to the public API, and fix the compilation. Result: No more left-overs to clean up after #13285 Co-authored-by: Norman Maurer <norman_maurer@apple.com>
Motivation:
SLF4J has been the defacto standard logging API in the Java world for a while. Normally we don't like to expose vendor APIs, but I think we can make an exception in this case. By using it directly, we can get rid of our own logging API code that isn't inherently relevant to what Netty does. It also means we can more easily make use of more advanced logging features like MDC and LoggingEventBuilders.
Modification:
Remove our internal logging API and use SLF4J everywhere. Switch back from log4j to using logback for our testing.
Result:
Less code to maintain, and everyone gets to use the same logging API.