common mistakes in this simple program

Ian Kelly ian.g.kelly at
Mon Feb 29 18:39:37 EST 2016

On Mon, Feb 29, 2016 at 4:14 PM, Cameron Simpson <cs at> wrote:
> Another remark here: if you're going to log, log the exception as well:
>     logging.error("something went wrong: %s", e)
> Ian's example code is nice and simple to illustrate "log and then reraise"
> but few things are as annoying as log files reciting "something went wrong"
> or the equivalent without any accompanying context information.

The proper way to pass in the exception is as a keyword argument:

logging.error("something went wrong", exc_info=e)

But I actually meant to use logging.exception, which handles this automatically.

More information about the Python-list mailing list