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

Overwriting exc_info in `exception()` #149

Closed
Hardtack opened this Issue Jan 14, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@Hardtack
Copy link

Hardtack commented Jan 14, 2018

structlog set the exc_info keyword argument to True in exception() (

def exception(self, event=None, *args, **kw):
"""
Process event and call :meth:`logging.Logger.error` with the result,
after setting ``exc_info`` to `True`.
"""
kw['exc_info'] = True
return self.error(event, *args, **kw)
)
This always make logger to load exc_info from sys.exc_info(). But sometimes, I want to log exception with another exc_info.
I surely can use error() instead. But logging module, the builtin logging library of Python, does not overwrite given exc_info and just give default value for that.

def exception(msg, *args, exc_info=True, **kwargs):
    """
    Log a message with severity 'ERROR' on the root logger, with exception
    information. If the logger has no handlers, basicConfig() is called to add
    a console handler with a pre-defined format.
    """
    error(msg, *args, exc_info=exc_info, **kwargs)

The difference between structlog and logging module makes user confuse.
I've been used builtin logging library for a long time, and I've always used exception() for logging exc_info. So I mistakenly use exception() with exc_info very often.
Could you make structlog not to overwrite given exc_info?

Just like this

def exception(self, event=None, *args, **kw):
    """
    Process event and call :meth:`logging.Logger.error` with the result,
    after setting ``exc_info`` to `True`.
    """
    kw.setdefault('exc_info', True)
    return self.error(event, *args, **kw)
@hynek

This comment has been minimized.

Copy link
Owner

hynek commented Jan 14, 2018

It sounds reasonable to make it conditional.

@hynek hynek closed this in 8dc9610 Jan 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.