-
Notifications
You must be signed in to change notification settings - Fork 657
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
Generate log message in advance #3571
Conversation
@raccoonback Thanks for the PR! @Test
void testLogFormat() {
Channel channel = new EmbeddedChannel();
useVerboseConsoleLoggers();
try {
InstrumentedPool<? extends Connection> pool = mock(InstrumentedPool.class);
InstrumentedPool.PoolMetrics metrics = mock(InstrumentedPool.PoolMetrics.class);
when(pool.metrics()).thenReturn(metrics);
logPoolState(channel, pool, "log message");
logPoolState(channel, pool, "log message", new Exception("test log format"));
}
finally {
resetLoggerFactory();
Connection.from(channel).dispose();
}
} |
@violetagg Yes, I'll check it out! |
aba22b7
to
c8eb560
Compare
@violetagg |
@raccoonback That's interesting When I'm using I'm seeing
When I'm using I'm seeing also the exception
Can you share the output that you are seeing? |
@violetagg when useing [DEBUG] (Test worker) Using Verbose Console logging
[DEBUG] (Test worker) [embedded, L:embedded - R:embedded] log message, now: 0 active connections, 0 inactive connections and 0 pending acquire requests.
[DEBUG] (Test worker) [embedded, L:embedded - R:embedded] log message, now: 0 active connections, 0 inactive connections and 0 pending acquire requests. when useing 08:19:01.030 [Test worker] DEBUG r.n.r.PooledConnectionProvider - [embedded, L:embedded - R:embedded] log message, now: 0 active connections, 0 inactive connections and 0 pending acquire requests.
08:19:01.037 [Test worker] DEBUG r.n.r.PooledConnectionProvider - [embedded, L:embedded - R:embedded] log message, now: 0 active connections, 0 inactive connections and 0 pending acquire requests.
java.lang.Exception: test log format
at reactor.netty.resources.DefaultPooledConnectionProviderTest.testLogFormat(DefaultPooledConnectionProviderTest.java:590)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:767)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) |
Here is what I’ve found so far:
public PrintStream format(String format, Object ... args) {
try {
synchronized (this) {
ensureOpen();
if ((formatter == null)
|| (formatter.locale() != Locale.getDefault()))
formatter = new Formatter((Appendable) this);
formatter.format(Locale.getDefault(), format, args);
}
} catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
} catch (IOException x) {
trouble = true;
}
return this;
} As a result, when |
@violetagg The above case appears to be a |
@raccoonback Please wait, there is no issue with reactor-core, I just wanted to point that we provide 5 arguments for 4 placeholders. Depending on the different implementations this behaves differently - some may omit the Throwable, some may try to handle the Throwable and as in the reported issue, the logging implementation may even print bad pattern. |
@violetagg
log.debug(
format(channel, "{}, now: {} active connections, {} inactive connections and {} pending acquire requests."),
msg,
metrics.acquiredSize(),
metrics.idleSize(),
metrics.pendingAcquireSize()
);
if(t != null) {
log.debug("", t);
}
String message = new StringJoiner(", ")
.add(msg)
.add("now: " + metrics.acquiredSize() + " active connections")
.add(metrics.idleSize() + " inactive connections and " + metrics.pendingAcquireSize() + " pending acquire requests.")
.toString();
if(t != null) {
log.debug(format(channel, message), t);
}
class LogUtils {
// ...
} Do you think any of these approaches would work best? Or do you have any other suggestions we could consider? |
c8eb560
to
ab6ac80
Compare
ab6ac80
to
c91f773
Compare
@violetagg |
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.
Thanks for the PR!
Add separate handling for Throwable when available. Fixes: #3561 Co-authored-by: Violeta Georgieva <[email protected]>
I back ported the fix to |
Add separate handling for Throwable when available.
Fixes: #3561