On Mon, Dec 13, 2010 at 8:45 AM, vinay.sajip <python-check...@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 | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com