Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103769

Re: common mistakes in this simple program

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: common mistakes in this simple program
Date 2016-02-29 16:39 -0700
Message-ID <mailman.50.1456789219.20602.python-list@python.org> (permalink)
References <CALwzidn8-HDrGSqZT2ODxhdNYL7yFt5hdmC8RnB4WC=gkD4Wtg@mail.gmail.com> <20160229231421.GA71350@cskk.homeip.net>

Show all headers | View raw


On Mon, Feb 29, 2016 at 4:14 PM, Cameron Simpson <cs@zip.com.au> 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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: common mistakes in this simple program Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-29 16:39 -0700

csiph-web