TwP / logging

A flexible logging library for use in Ruby programs based on the design of Java's log4j library.
https://rubygems.org/gems/logging
MIT License
530 stars 101 forks source link

Make context inheritance optional #160

Closed TwP closed 7 years ago

TwP commented 7 years ago

This code adds an environment flag that can be used to disable or enabled context inheritance. The diagnostic contexts are stored in a thread local variable. To inhert this context between threads, we have to override the new, start, and fork methods so that we have a handle on the parent thread's context.

The unfortunate downside of this is that we end up with Logging calls in backtraces for some exceptions involving threads. This can lead to confusion.

You can set the environment variable LOGGING_INHERIT_CONTEXT to false to disable this feature if you do not need it.

LOGGING_INHERIT_CONTEXT=false ruby your_code.rb

fixes #155

/cc @ivoanjo

ivoanjo commented 7 years ago

Wow, this looks very good! I'm away from my laptop until the end of the week, but I'll definitely test it and report back. Thanks!