A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-December/106758.html below:

[Python-Dev] [Python-checkins] r87202 - python/branches/py3k/Doc/library/logging.rst

[Python-Dev] [Python-checkins] r87202 - python/branches/py3k/Doc/library/logging.rstNick Coghlan ncoghlan at gmail.com
Mon Dec 13 04:45:50 CET 2010
On Mon, Dec 13, 2010 at 8:45 AM, vinay.sajip <python-checkins at python.org> wrote:
> +to get the value which you'll pass to :func:`basicConfig` via the *level*
> +argument. You may want to error check any user input value, perhaps as in the
> +following example::
> +
> +   # assuming loglevel is bound to the string value obtained from the
> +   # command line argument. Convert to upper case to allow the user to
> +   # specify --log=DEBUG or --log=debug
> +   numeric_level = getattr(logging, loglevel.upper(), None)
> +   assert numeric_level is not None, 'Invalid log level: %s' % loglevel
> +   logging.basicConfig(level=numeric_level, ...)

Minor nit - using asserts to check user input is generally a bad idea.
A more explicit check might be a better example:

if not isinstance(numeric_level, int):
   raise ValueError('Invalid log level: %s' % loglevel)

This also covers the case where someone does something weird like pass
in "basic_format" as a logging level.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4