Created
November 30, 2016 14:05
-
-
Save enricobacis/83ca7bf163b27e95eb28288e0756f8cc to your computer and use it in GitHub Desktop.
Overwrite python's logging.error to log also args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
import logging | |
import inspect | |
# save the old logging.error function | |
__logging_error = logging.error | |
@wraps(logging.error) | |
def error(msg, *args, **kwargs): | |
__logging_error(msg, *args, **kwargs) | |
caller = inspect.stack()[1] | |
caller_frame = caller[0] | |
__logging_error('args: %s' % caller_frame.f_locals) | |
# overwrite the default logging.error | |
logging.error = error | |
def add(x, y): | |
logging.error('this is an error') | |
return x + y | |
add(4, 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment