From c1703357e8bbc965ffadd25d1df99bb481532c3a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 28 Jan 2021 16:51:06 -0800 Subject: [PATCH] Add main_fallback name to vlogging.getLogger. --- voussoirkit/vlogging.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/voussoirkit/vlogging.py b/voussoirkit/vlogging.py index faeb482..2bf15a4 100644 --- a/voussoirkit/vlogging.py +++ b/voussoirkit/vlogging.py @@ -8,8 +8,15 @@ _getLogger = getLogger LOUD = 1 -def getLogger(*args, **kwargs): - log = _getLogger(*args, **kwargs) +def getLogger(name=None, main_fallback=None): + # Normally it is best practice to use getLogger(__name__), but when running + # a script directly you'll see "__main__" in the output, which I think is + # ugly and unexpected for anyone who doesn't know what's going on behind + # the scenes. But hardcoding your logger name is not good either. + # So, main_fallback is used to present your preferred name in case of main. + if name == '__main__' and main_fallback is not None: + name = main_fallback + log = _getLogger(name) add_loud(log) return log