diff options
author | Doug Freed <dwfreed@mtu.edu> | 2024-07-29 22:24:44 +0000 |
---|---|---|
committer | Andreas K. Hüttel <dilfridge@gentoo.org> | 2024-07-30 13:08:12 +0200 |
commit | 27035bc1a25e57fc3127db865b999acf15bd1697 (patch) | |
tree | 78c5c3aea99d478d09fde804585001a41373ab47 | |
parent | stagebase: create profile link for ROOT too (diff) | |
download | catalyst-27035bc1a25e57fc3127db865b999acf15bd1697.tar.gz catalyst-27035bc1a25e57fc3127db865b999acf15bd1697.tar.bz2 catalyst-27035bc1a25e57fc3127db865b999acf15bd1697.zip |
log: hide our functions and include line numbers
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
-rw-r--r-- | catalyst/log.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/catalyst/log.py b/catalyst/log.py index ee124392..fb852f2f 100644 --- a/catalyst/log.py +++ b/catalyst/log.py @@ -20,6 +20,11 @@ class CatalystLogger(logging.Logger): def _log(self, level, msg, args, **kwargs): """If given a multiline message, split it""" + + # Increment stacklevel to hide this function call + stacklevel = kwargs.get("stacklevel", 1) + kwargs["stacklevel"] = stacklevel + 1 + # We have to interpolate it first in case they spread things out # over multiple lines like: Bad Thing:\n%s\nGoodbye! msg %= args @@ -44,11 +49,21 @@ logging.addLevelName(NOTICE, 'NOTICE') # The API we expose to consumers. def notice(msg, *args, **kwargs): """Log a notice message""" + + # Increment stacklevel to hide this function call + stacklevel = kwargs.get("stacklevel", 1) + kwargs["stacklevel"] = stacklevel + 1 + logger.log(NOTICE, msg, *args, **kwargs) def critical(msg, *args, **kwargs): """Log a critical message and then exit""" + + # Increment stacklevel to hide this function call + stacklevel = kwargs.get("stacklevel", 1) + kwargs["stacklevel"] = stacklevel + 1 + status = kwargs.pop('status', 1) logger.critical(msg, *args, **kwargs) sys.exit(status) @@ -110,7 +125,7 @@ def setup_logging(level, output=None, debug=False, color=None): # The good stuff. fmt = '%(asctime)s: %(levelname)-8s: ' if debug: - fmt += '%(filename)s:%(funcName)s: ' + fmt += '%(filename)s:%(funcName)s:%(lineno)d: ' fmt += '%(message)s' # Figure out where to send the log output. |