Add some docstrings.
This commit is contained in:
parent
63689e02c0
commit
03e5830133
1 changed files with 20 additions and 0 deletions
|
@ -14,6 +14,20 @@ def add_loud(log):
|
||||||
log.loud = lambda *args, **kwargs: log.log(LOUD, *args, **kwargs)
|
log.loud = lambda *args, **kwargs: log.log(LOUD, *args, **kwargs)
|
||||||
|
|
||||||
def get_level_by_argv(argv):
|
def get_level_by_argv(argv):
|
||||||
|
'''
|
||||||
|
If any of the following arguments are present in argv, return the
|
||||||
|
corresponding log level along with a new copy of argv that has had the
|
||||||
|
argument string removed.
|
||||||
|
|
||||||
|
Since we are removing the argument, your argparser should not have options
|
||||||
|
with these same names.
|
||||||
|
|
||||||
|
--loud: LOUD
|
||||||
|
--debug: DEBUG
|
||||||
|
--quiet: ERROR
|
||||||
|
--silent: 99999999999
|
||||||
|
none of the above: INFO
|
||||||
|
'''
|
||||||
argv = argv[:]
|
argv = argv[:]
|
||||||
|
|
||||||
if '--loud' in argv:
|
if '--loud' in argv:
|
||||||
|
@ -34,6 +48,12 @@ def get_level_by_argv(argv):
|
||||||
return (level, argv)
|
return (level, argv)
|
||||||
|
|
||||||
def set_level_by_argv(log, argv):
|
def set_level_by_argv(log, argv):
|
||||||
|
'''
|
||||||
|
This function is helpful for single-file scripts where you instantiate the
|
||||||
|
logger in the global scope, and use this function to set its level
|
||||||
|
according to the "--debug" flags in argv, then pass the rest of argv to
|
||||||
|
your argparser.
|
||||||
|
'''
|
||||||
basicConfig()
|
basicConfig()
|
||||||
|
|
||||||
(level, argv) = get_level_by_argv(argv)
|
(level, argv) = get_level_by_argv(argv)
|
||||||
|
|
Loading…
Reference in a new issue