Skip to content
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

Mutable Type Serialization #5

Open
vjkoskela opened this issue Jun 4, 2015 · 0 comments
Open

Mutable Type Serialization #5

vjkoskela opened this issue Jun 4, 2015 · 0 comments

Comments

@vjkoskela
Copy link
Member

The serialization of all values, whether for context or data, is performed by the encoder. If the encoder is setup on an appender which is executed asynchronously, then the encoding is performed in a different thread. For more information about Logback Appenders see:

http://logback.qos.ch/manual/appenders.html

If the value is immutable it is guaranteed to be the same when serialized asynchronously even if it occurs much later in the program's execution. However, mutable values may change state between the time the log message is created and the message is serialized. Thus, it is possible to log a message with the "wrong" (perhaps more correctly, misleading or mismatched) data values. However, the serialization in another thread actually improves the performance of your program versus formatting a String inline (especially if that log message is discarded).

The framework should be extended to support upfront serialization of mutable types. To put it another way, to detect immutable types and only pass those as-is for delayed serialization while serializing mutable types (perhaps to JsonNode) before dispatching to the appender. To mark immutable types we should use JSR-305:

https://code.google.com/p/jsr-305/source/browse/trunk/ri/src/main/java/javax/annotation/concurrent/Immutable.java
http://mvnrepository.com/artifact/com.google.code.findbugs/jsr305

This will be relatively straight forward when using the LogBuilder but more difficult (possibly impossible) to do in a general way with log statements using the markers. Whatever the limitations they should be clearly documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant