Skip to content
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

Inconsistency of BoundLogger with logging.Logger #190

Closed
decaz opened this issue Nov 30, 2018 · 6 comments
Closed

Inconsistency of BoundLogger with logging.Logger #190

decaz opened this issue Nov 30, 2018 · 6 comments

Comments

@decaz
Copy link
Contributor

decaz commented Nov 30, 2018

There are no public attributes of logging.Logger available within BoundLogger (propagate for instance).
Also there are no attributes or methods of logging.Filterer (which is parent class of logging.Logger) available within BoundLogger.

@hynek
Copy link
Owner

hynek commented Dec 1, 2018

That’s on purpose…what would you expect them to do?

@decaz
Copy link
Contributor Author

decaz commented Dec 2, 2018

@hynek I expect them to proxy to original attributes or methods.

The problem occured when I tried to replace my Flask app's default logger with BoundLogger. I use raven library and it checks propagate attribute of logger: https://github.com/getsentry/raven-python/blob/master/raven/contrib/flask.py#L297. Of course it leads to an error.

@decaz
Copy link
Contributor Author

decaz commented Jan 14, 2019

Another one example of logger's name attribute usage: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web.py#L394 (raises exception if BoundLogger was specified at aiohttp.web.run_app(access_log=...)).

@hynek
Copy link
Owner

hynek commented Jan 16, 2019

I suppose the easiest way for you would be to use the dynamic default logger that will just proxy everything to the wrapped logger? I’m not sure it’s worth it to play whack-a-mole with the whole API to catch all possible usages. 🤔

@decaz
Copy link
Contributor Author

decaz commented Jan 16, 2019

What do you mean by "dynamic default logger" and how it can be used with the BoundLogger? Currently I just sublclassed BoundLogger and implemented methods I need to use.

@hynek
Copy link
Owner

hynek commented Jan 16, 2019

If I’m not mistaken, it should be enough to not configure wrapper_class. Then you'll get https://www.structlog.org/en/stable/api.html#structlog.BoundLogger which will forward every unknown method call (i.e. everything except bind/unbind/new) to the wrapped logger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants