From 9349527e3f98bdc1cf7854ffe4958e301babd967 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Thu, 2 Mar 2023 16:03:56 -0800 Subject: [PATCH] Cleanup. --- src/pyutils/logging_utils.py | 38 +----------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/pyutils/logging_utils.py b/src/pyutils/logging_utils.py index d3102c8..5d1ec8b 100644 --- a/src/pyutils/logging_utils.py +++ b/src/pyutils/logging_utils.py @@ -470,24 +470,6 @@ class OnlyInfoFilter(logging.Filter): return record.levelno == logging.INFO -def prepend_all_logger_messages( - prefix: str, logger: logging.Logger -) -> logging.LoggerAdapter: - """Helper method around the creation of a LoggerAdapter that prepends - a given string to every log message produced. - - Args: - prefix: the message to prepend to every log message. - logger: the logger whose messages to modify. - - Returns: - A new logger wrapping the old one with the given behavior. - The old logger will continue to behave as usual; simply drop - the reference to this wrapper when it's no longer needed. - """ - return PrependingLogAdapter.wrap_logger(prefix, logger) - - class PrependingLogAdapter(logging.LoggerAdapter): def process(self, msg, kwargs): return f'{self.extra.get("prefix", "")}{msg}', kwargs @@ -510,24 +492,6 @@ class PrependingLogAdapter(logging.LoggerAdapter): return PrependingLogAdapter(logger, {"prefix": prefix}) -def append_all_logger_messages( - suffix: str, logger: logging.Logger -) -> logging.LoggerAdapter: - """Helper method around the creation of a LoggerAdapter that appends - a given string to every log message produced. - - Args: - suffix: the message to prepend to every log message. - logger: the logger whose messages to modify. - - Returns: - A new logger wrapping the old one with the given behavior. - The old logger will continue to behave as usual; simply drop - the reference to this wrapper when it's no longer needed. - """ - return AppendingLogAdapter.wrap_logger(suffix, logger) - - class AppendingLogAdapter(logging.LoggerAdapter): def process(self, msg, kwargs): return f'{msg}{self.extra.get("suffix", "")}', kwargs @@ -565,7 +529,7 @@ class LoggingContext(contextlib.ContextDecorator): * Add a prefix string to log messages * Add a suffix string to log messages - .. warning:: + .. note:: Unfortunately this can't be used to dynamically change the defaut logging level because of a conflict with -- 2.45.0