FIX: Stop env mutation to allow all chained loggers to have the same env #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Logster allows the backtrace of a message to be provided via its
env
. This can be done by setting theenv
hash in the current thread's storage like soThread.current[Logster::Logger::LOGSTER_ENV] = env_with_backtrace
. Logster also has the ability to chain multiple loggers that do different things. The problem here is that if one of the chained loggers mutate something, that change may cause the remaining loggers to behave differently.An example of this problem is
base_store.rb
at line 163 it does this:backtrace = env.delete(:backtrace)
. This affects us at Discourse where we ship all the logs from sites we host to a central place by adding a logger to logster's chain. The problem we're seeing is that the same log message has a completely different backtraces on the central website vs the website that originated the log message. The reason for this is 1) some messages rely on passing the backtrace viaenv
, and 2) the env mutations that happen at line 163 inbase_store.rb
. This PR fixes the problem bydup
ingenv
before deleting:backtrace
from it (we still need to delete:backtrace
fromenv
because we don't want the backtrace to actually be part ofenv
).