-
Notifications
You must be signed in to change notification settings - Fork 184
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
Set the correct log level for wire logging and h2 frame logging #1123
Conversation
...t-netty-internal/src/main/java/io/servicetalk/transport/netty/internal/NettyLoggerUtils.java
Show resolved
Hide resolved
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.
👍
...t-netty-internal/src/main/java/io/servicetalk/transport/netty/internal/NettyLoggerUtils.java
Show resolved
Hide resolved
* @param loggerName The logger name to lookup. | ||
* @return Netty's {@link LogLevel} corresponding to the SL4J log level for {@code loggerName}. | ||
*/ | ||
public static LogLevel getNettyLogLevel(String loggerName) { |
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.
A behavior that is useful is to enable wire logging in code but disable it using logger levels. I think this will always enable wire logging if it is enabled in code, is that correct?
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.
Good question! Most of the logger implementations also support OFF
that disables logging [1, 2] from the logger config. But we need to adjust getNettyLogLevel
method to support it.
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 configuration can be modified to accommodate this, an appender can include a threshold level. I will enhance our test log4j2-test.xml
to accommodate this.
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 sure I am following the motivation now. Threshold filter is specific to log4j, so not ideal that we have to depend on that for the expected behavior.
Why not just let the user specify the level at which they want to log?
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.
Threshold filter was one example of how this can be handled in configuration, setting the logging value to OFF is another example. Specifying the log level programmatically requires additional API surface area (e.g. log level API, propagation of log level) which seems redundant if the configuration has to be setup correctly to enable/disable the logger anyways. This change still allows for specifying the logger in builder code and disable it via config, which I think was your initial concern?
...t-netty-internal/src/main/java/io/servicetalk/transport/netty/internal/NettyLoggerUtils.java
Outdated
Show resolved
Hide resolved
Motivation: When enableWireLogging and h2 frameLogger are set on the builder we always log at TRACE level regardless of what level the logging configuration specifies. The h2 frameLogger has conditional logic which limits the amount of data logged for levels less than TRACE, and it is generally unexpected to log at a different level than configured by the user. Modifications: - When Http2FrameLogger and LoggingHandler are created we should get the log level from SL4J and pass the translated Netty LogLevel upon construction Result: Debug logging uses the same log level as configured by the user.
52a6888
to
8894e33
Compare
@@ -21,14 +21,6 @@ | |||
</Console> | |||
</Appenders> | |||
<Loggers> | |||
<!-- | |||
This is an example of how to configure logging of wire events: | |||
1. Add a Logger with `TRACE` level; |
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.
since there is no more strict requirement on the log level, we have an opportunity to simplify the examples. Log4j can be configured in many ways (filters, multiple appenders, using different loggers, etc.) and I don't think this is central to understanding servicetalk.
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.
👍
Like new approach. It gives more flexibility. For example, in tests we don't need to worry about removing enableWireLogging
before committing changes (always was the pain) because the wire logger is off by default and controlled by system property.
@@ -34,11 +37,14 @@ | |||
* @param loggerName The name of the logger to log wire events. | |||
*/ | |||
public WireLoggingInitializer(final String loggerName) { | |||
loggingHandler = new LoggingHandler(loggerName, TRACE); | |||
LogLevel logLevel = getNettyLogLevel(loggerName); | |||
loggingHandler = logLevel != null ? new LoggingHandler(loggerName, logLevel) : null; |
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.
Just a suggestion; feel free to ignore.
This approach precludes dynamic log level manipulation for existing channels. I think we should always add the handler if user opts-in to it using the builder setting.
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.
logLevel == null
will only if the logging level can't be mapped to a Netty LogLevel
(e.g. "OFF"). The user's logging config can set the logging level set to a valid level (e.g. not "OFF") and use a filter to achieve the dynamic enable/disable of logs on pre-existing channels.
Motivation: Wire logger and h2 frame logger are controlled by the logger configuration after apple#1123. It allows us to use these logger names in tests and enabled them via system property when required for local debugging. Having 2 different logger names for client and server controlled by a single system property does not help much. We can use thread name to understand if a logger statement belongs to a client or to a server. A single logger name simplifies usage in tests. Modifications: - Keep only a single `servicetalk-tests-wire-logger` logger name; - Add `servicetalk-tests-h2-frame-logger` logger name and `servicetalk.logger.h2FrameLogLevel` system property to control visibility for h2 frames; - Update all tests to use new names; Result: Separate system property to control wire logger and h2 frame logger.
Motivation: Wire logger and h2 frame logger are controlled by the logger configuration after #1123. It allows us to use these logger names in tests and enabled them via system property when required for local debugging. Having 2 different logger names for client and server controlled by a single system property does not help much. We can use thread name to understand if a logger statement belongs to a client or to a server. A single logger name simplifies usage in tests. Modifications: - Keep only a single `servicetalk-tests-wire-logger` logger name; - Add `servicetalk-tests-h2-frame-logger` logger name and `servicetalk.logger.h2FrameLogLevel` system property to control visibility for h2 frames; - Update all tests to use new names; Result: Separate system property to control wire logger and h2 frame logger.
Motivation:
When enableWireLogging and h2 frameLogger are set on the builder we
always log at TRACE level regardless of what level the logging
configuration specifies. The h2 frameLogger has conditional logic which
limits the amount of data logged for levels less than TRACE, and it is
generally unexpected to log at a different level than configured by the
user.
Modifications:
log level from SL4J and pass the translated Netty LogLevel upon
construction
Result:
Debug logging uses the same log level as configured by the user.