From e3d9336383ac8c0c5cff55dbf1edcaa4a5680c62 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 8 Nov 2020 20:12:05 -0800 Subject: [PATCH] Pull code out to separate function get_level_by_argv. --- voussoirkit/vlogging.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/voussoirkit/vlogging.py b/voussoirkit/vlogging.py index a5d167f..b106711 100644 --- a/voussoirkit/vlogging.py +++ b/voussoirkit/vlogging.py @@ -13,20 +13,27 @@ def add_loud(log): addLevelName(LOUD, 'LOUD') log.loud = lambda *args, **kwargs: log.log(LOUD, *args, **kwargs) -def set_level_by_argv(log, argv): - basicConfig() +def get_level_by_argv(argv): argv = argv[:] if '--loud' in argv: - log.setLevel(LOUD) + level = LOUD argv.remove('--loud') elif '--debug' in argv: - log.setLevel(DEBUG) + level = DEBUG argv.remove('--debug') elif '--quiet' in argv: - log.setLevel(ERROR) + level = ERROR argv.remove('--quiet') else: - log.setLevel(INFO) + level = INFO + + return (level, argv) + +def set_level_by_argv(log, argv): + basicConfig() + + (level, argv) = get_level_by_argv(argv) + log.setLevel(level) return argv