Suggestion for using stdlib BoundLogger with third-party apps. #95
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.
Hi there,
Here are some suggestions to improve stdlib. It allows to use the stdlib.BoundLogger, even when defining a root handler (to pass third-party apps logs through structlog's pipeline). Not sure my approach is really logical and elegant though (maybe closer to a POC) and suggestions/improvements are welcome.
Add a
stdlib.Handler
class that helps forward third-party apps logs through structlog. May fit to most use cases. However, can lead to recursion issues if you persist on usingstdlib.LogFactory
. To overcome this, I did some extra-work (see second bullet-point).Typical use-case: output third-party apps + structlog logs to stdout.
stdlib._HandlerWrapper
class and astdlib.wrap_handler
function that allows to output structlog log through logging modules handlers (this required some more changes instdlib.LoggerFactory
to work properly). This wrapper prevents structlog from recursing.Typical use-case: output third-party apps through structlog, and even output everything to vanilla handlers.
Thus, this allows to use stdlib.filter_by_level and probably some other stuff I did not think of.
Cheers.