On Mon, Dec 13, 2010 at 11:22 AM, Robert Kern <robert.k...@gmail.com> wrote: > level = getattr(logging, opt.logLevel)
While this is the approach I would recommend, it does have a couple of downsides: 1. An upper() call is also needed to allow strings like "info" instead of "INFO": 2. If an integer is available, it would be nice to return it unmodified (or, if we ever get named values in the standard library, convert it to that) 3. The asymmetry with "logging.getLevelName" grates a bit So it would be far more obvious if there was a "logging.getLevel" counterpart to "logging.getLevelName" that looked something like: def getLevel(level): try: return operator.index(level) # Integers and equivalents except TypeError: pass try: key = level.upper() except Exception as ex: raise TypeError("Log level must be an integer or string") from ex return globals()[key] > level = logging._levelNames[opt.logLevel] That doesn't work (_levelNames maps from integers to strings, we want the mapping from strings to integers and it is only the module globals that provides that). Regards, 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