Created
February 15, 2016 20:29
-
-
Save westurner/1b4d0e79d323e04ce612 to your computer and use it in GitHub Desktop.
loglevels.py: logging._levelNames { (0) NOTSET ; (10) DEBUG ; (20) INFO ; (30) WARN / WARNING ; (40) ERROR ; (50) CRITICAL / FATAL }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import logging | |
### | |
def addLevelName__TRACE(): | |
logging.addLevelName(8, 'TRACE') | |
### | |
def get_default_loglevel__dir(): | |
""" | |
:: | |
[(0, NOTSET), | |
(10, DEBUG), | |
(20, INFO), | |
(30, WARN), | |
(30, WARNING), | |
(40, ERROR), | |
(50, CRITICAL), | |
(50, FATAL)] | |
""" | |
return sorted( | |
(getattr(logging, x), x) for x in dir(logging) | |
if isinstance(getattr(logging, x), int) | |
and (x == x.upper())) | |
def get_default_loglevel__levelNames(): | |
""" | |
:: | |
{0: NOTSET, | |
10: DEBUG, | |
20: INFO, | |
30: WARNING, | |
40: ERROR, | |
50: CRITICAL, | |
CRITICAL: 50, | |
DEBUG: 10, | |
ERROR: 40, | |
INFO: 20, | |
NOTSET: 0, | |
WARN: 30, | |
WARNING: 30} | |
""" | |
return [(k,v) for k,v in logging._levelNames.items() if isinstance(k, int)] | |
def print_loglevels(): | |
print("### DEFAULTS""") | |
levels_dir = get_default_loglevel__dir() | |
for leveltuple in levels_dir: | |
print(repr(leveltuple)) | |
print("### logging._levelNames""") | |
levels_levelNames = get_default_loglevel__levelNames() | |
for leveltuple in levels_levelNames: | |
print(repr(leveltuple)) | |
def main(argv=None): | |
if not argv: | |
print_loglevels() | |
return 0 | |
else: | |
for levelNames_key in argv: | |
try: | |
levelNames_key = int(levelNames_key) | |
except TypeError: | |
pass | |
value = logging._levelNames.get(levelNames_key) | |
print(value) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment