Skip to content

Instantly share code, notes, and snippets.

@enricobacis
Created November 30, 2016 14:05
Show Gist options
  • Save enricobacis/83ca7bf163b27e95eb28288e0756f8cc to your computer and use it in GitHub Desktop.
Save enricobacis/83ca7bf163b27e95eb28288e0756f8cc to your computer and use it in GitHub Desktop.
Overwrite python's logging.error to log also args
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