-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Improving make_filtering_bound_logger's compatibility with the stdlib logger #469
Comments
As noted in hynek#469, `make_filtering_bound_logger` was returning a `BoundLoggerBase` with minimal functionality. These changes refactor the `BoundLogger` definition to avoid circular dependencies and allow for it's use in `make_filtering_bound_logger`.
Let's discuss this here, before delving into #470. What you're doing there is basically re-implementing parts of our stdlib integration. I'm sympathetic to wanting a true drop-in replacement, but that's what literally what https://www.structlog.org/en/latest/api.html#structlog.stdlib.BoundLogger is for (along with all the goodies). If you want to gradually switch away from stdlib APIs, but use the faster loggers from Does that make sense? Essentially: import structlog
import logging
FL = structlog.make_filtering_bound_logger(logging.INFO)
class StubFilteringLogger(FL):
@property
def disabled(self):
return False
structlog.configure(wrapper_class=StubFilteringLogger)
logger = structlog.get_logger()
logger.info("hi", disabled=logger.disabled) I might be open to add such a stub logger to structlog, but I'm not sure if it's possible those stubs make universally useful? |
So my intent was to we-use the existing implementation instead of mirroring the behavior in order to get something that would be performant when filtering leveled log messages but compatible with stdlib logger use I'm encountering "in the wild". I started with generating my own Alternatively would a |
I should note that my use case here isn't gradual replacement. It's supporting third party libraries and frameworks that use the stdlib logger interface. If I had control I'd just use structlog natively everywhere. |
While trying to use
structlog
as a drop in for the stdlib logger usage inslack_bolt
, I encountered a variety of errors stemming from missing wrapper implementations.Error example:
The root cause appears to be
make_filtering_bound_logger
's usage ofBoundLoggerBase
instead of the fully implementedBoundLogger
.BoundLogger
itself is missing thefilters
wrapper, but that is trivial to fix.BoundLoggerBase
is missing all of the wrapper logic and that appears intentional.With an analog to
BoundLogger
implemented I am able to use structlog as a drop-in replacement for the standard logger.I'll be tying in a pull request with a proposed solution.
The text was updated successfully, but these errors were encountered: