Make SilencedLogger thread safe
Rails logger silencer code was thread safe for some time:
But this has been refactored in Rails 5.0 and thread safety is now part of logger instead of silencer:
The patch made assumption that all Rails applications are using Rails logging stack, but that's not the case for Foreman - we rely on much more flexible "logging" gem (https://github.com/TwP/logging) which does not implement this type of thread safety for levels.
Foreman has its own logging delegator called SilencedLogger and the code there was never thread safe, concurrent sprockets requests are now using silence method which is not thread safe at all, with logging gem this leads to level set to ERROR (the default) after few requests in development mode which renders Foreman unusable (no debug logging output). This patch uses the same technique and stores temporary levels into thread-only context, so on concurrent access there are no incorrect readouts.
Refs #22354 - Don't instance_eval at every instance creation
Before this patch, we were defining the methods at every instance
creation. This means potential performance issues, as defining new
methods causes the method lookup cache to get dropped.
I needed to move the time for loading the silencer a bit later so that
the `Logging::LEVELS` are already initialized (as they are empty at the