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
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