-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Improve implementations of LogEvent.toImmutable()
and ReusableMessage.memento()
#3171
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
base: 2.x
Are you sure you want to change the base?
Conversation
The implementations of `LogEvent.toImmutable()` either use serialization or one of the `Log4jLogEvent.Builder` constructors and custom per class code. This PR: - Redirects all implementation of `LogEvent.toImmutable` to the `Builder(LogEvent)` constructor (except `Log4jLogEvent.toImmutable()`) - Improve the constructor to create really immutable and thread-safe instances. - Removes the usage of `ThrowableProxy` for purposes not related to serialization. - Fixes some implementations of `ReusableMessage.memento()`. - Uses `ReusableMessage.memento()` instead of `ImmutableMessage` where applicable.
private void initTranslatorThreadValues(final RingBufferLogEventTranslator translator) { | ||
// constant check should be optimized out when using default (CACHED) | ||
if (THREAD_NAME_CACHING_STRATEGY == ThreadNameCachingStrategy.UNCACHED) { | ||
translator.updateThreadValues(); | ||
} | ||
} |
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.
Instances of RingBufferLogEventTranslator
are always used on the same thread that created them.
…hrowable-proxy-clean-up
@@ -128,7 +128,9 @@ public <S> void forEachParameter(final ParameterConsumer<S> action, final S stat | |||
|
|||
@Override | |||
public Message memento() { | |||
return new ObjectMessage(obj); | |||
Message message = new ObjectMessage(obj); | |||
message.getFormattedMessage(); |
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 presume you make this call to trigger the stack trace capture. Would you mind documenting this, please? (Also in other message/*Message.java
changes.)
assertThat(other.getTimeMillis()).isEqualTo(12345); | ||
assertThat(other.getInstant().getNanoOfMillisecond()).isEqualTo(678); | ||
final LogEvent other = SerialUtil.deserialize(SerialUtil.serialize(evt)); | ||
assertThat(other.getLoggerName()).as("Logger name").isEqualTo(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.
Nit: I wouldn't add to the complexity with extra as()
calls, since the assertion failure line number precisely points to the associated field.
* @deprecated since 2.25.0. {@link RingBufferLogEventTranslator} instances should only be used on the thread that | ||
* created it. | ||
*/ | ||
@Deprecated |
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 we removed AsyncLogger::initTranslatorThreadValues
, usages of this method will result in undefined behavior. Shouldn't we throw an UnsupportedOE
in this method?
The implementations of
LogEvent.toImmutable()
either use serialization or one of theLog4jLogEvent.Builder
constructors and custom per class code.This PR:
LogEvent.toImmutable
to theBuilder(LogEvent)
constructor (exceptLog4jLogEvent.toImmutable()
)ThrowableProxy
for purposes not related to serialization.ReusableMessage.memento()
.ReusableMessage.memento()
instead ofImmutableMessage
where applicable.