[Python-Dev] Using logging in the stdlib and its unit tests (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Mon Dec 13 05:27:21 CET 2010
- Previous message: [Python-Dev] Using logging in the stdlib and its unit tests
- Next message: [Python-Dev] Using logging in the stdlib and its unit tests
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Dec 13, 2010 at 2:13 PM, Robert Kern <robert.kern at gmail.com> wrote:
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). At least in Python 2.6, it maps both ways. But then again, it is an implementation detail that should not be relied upon in your programs.
Ah, you're quite right - I didn't notice that when looking at the contents (the first entries happened to map levels to names)
I would suggest that there should be two dictionaries as part of the documented API, one mapping numbers to names and one mapping names to numbers. Or functions/methods returning said dictionaries. Having the entire mappings at hand is more useful than having functions that do the translation. They would allow you to auto-generate UIs (e.g. the help text for a --log-level argument or a radio box widget in a GUI). Having separate mappings makes them easier to work with than the 2.6-style levelNames mapping.
Definitely something worth considering for 3.3.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] Using logging in the stdlib and its unit tests
- Next message: [Python-Dev] Using logging in the stdlib and its unit tests
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]