sighalt / logdecorator

Move logging code out of your business logic with python decorators.
MIT License
73 stars 12 forks source link

log_exception doesn't want to log on level CRITICAL/FATAL #5

Closed Skazu closed 3 years ago

Skazu commented 5 years ago

Hello, the log_exception decorator tries to force me to log on level ERROR instead of CRITICAL/FATAL or any self defined level, if i use one of those levels i get the following warning: UserWarning: `log_exception` can only log into ERROR log level What's the intention behind this warning? Why is this decorator bound to this specific log level?

sighalt commented 5 years ago

Hi and thanks for the request.

log_exception uses logging.exception under the hood. Since logging.exception logs only to the ERROR log level, I decided to throw a user warning in order to avoid confusion, when the log messages are not logged to the given level. Please have a look at https://docs.python.org/3/library/logging.html#logging.exception for further information.

Skazu commented 5 years ago

Ah i see, but then whats the reason for the log_level constructor argument? Wouldn't it be more intuitive to drop this argument and stick hard to logging.ERROR in the super().__init__(...) call?

sighalt commented 5 years ago

Indeed, this is a bit confusing. I'll evaluate this as a candidate for some future release.

sighalt commented 5 years ago

This change will be available in logdecorator 2.2 and is already implemented in the release branch #7

sighalt commented 3 years ago

PR was merged into master branch.