structlog
structlog copied to clipboard
Cannot use PositionalArgumentsFormatter with FilteringBoundLogger
I was switching to using make_filtering_bound_logger when I noticed that using a custom Gunicorn logger (that basically maps to structlog logging) wasn't working anymore. The issue is that the logger is doing something like log.info("Starting gunicorn %s", __version__) which then caused an error:
TypeError: _make_filtering_bound_logger.<locals>.make_method.<locals>.meth() takes 2 positional arguments but 3 were given
I can open a PR to simply pass through *args as well (in the level and log methods) which should clear up the error, though I don't know if this could cause downstream issues.
This will need a bit more thought, perhaps make_filtering_bound_logger should move to stdlib so it can create a subclass of BoundLogger, rather than BoundLoggerBase? The BoundLogger class handles positional arguments properly so it can be used with PositionalArgumentsFormatter. It might make sense to move that code out of _log_levels.py anyways to avoid circular imports.
I think I need more context here – how did you manage to make gunicorn use make_filtering_bound_logger? The whole point of it is to have very fast level filters if you don't use stdlib, which has level filters built in?
Gunicorn allows you to specify a logger class to use: https://docs.gunicorn.org/en/stable/settings.html#logger-class, so by adapting it similar to what I found in this gist, I was able to have Gunicorn log with a structlog logger. However, I can't control how gunicorn calls their logger, and they still interface with it as if it was a stdlib logger.
hey sorry for the delay – would you mind checking if https://github.com/hynek/structlog/pull/454 fixes this?
Thanks, I haven't had a chance to fully test it but looking at the code, it looks like it should work! 🎉
@hynek Can I ask one small question? When this changes will be available? Just approximately 😉
The 22.2 is largely feature-complete, but I need to tie up a few strings in documentation (notably add a Celery recipe) and a bit of admin work. Shouldn't be too long, since I want it out too, but can't commit to a date.