From 2ec77f287bc0348d7a6217fcc6d403629b665f4e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 2 Nov 2020 23:18:53 -0800 Subject: [PATCH] Add vlogging.py. --- voussoirkit/vlogging.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 voussoirkit/vlogging.py diff --git a/voussoirkit/vlogging.py b/voussoirkit/vlogging.py new file mode 100644 index 0000000..a5d167f --- /dev/null +++ b/voussoirkit/vlogging.py @@ -0,0 +1,32 @@ +from logging import * + +_getLogger = getLogger + +LOUD = 1 + +def getLogger(*args, **kwargs): + log = _getLogger(*args, **kwargs) + add_loud(log) + return log + +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() + argv = argv[:] + + if '--loud' in argv: + log.setLevel(LOUD) + argv.remove('--loud') + elif '--debug' in argv: + log.setLevel(DEBUG) + argv.remove('--debug') + elif '--quiet' in argv: + log.setLevel(ERROR) + argv.remove('--quiet') + else: + log.setLevel(INFO) + + return argv