From ab64844aba3db6f8fb6a0204dee9b0dc617688d3 Mon Sep 17 00:00:00 2001 From: Enno Hermann Date: Tue, 2 Apr 2024 12:15:18 +0200 Subject: [PATCH] feat(utils.generic_utils): add custom formatter for logging to console --- TTS/utils/generic_utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/TTS/utils/generic_utils.py b/TTS/utils/generic_utils.py index 96edd29f..024d5027 100644 --- a/TTS/utils/generic_utils.py +++ b/TTS/utils/generic_utils.py @@ -129,6 +129,20 @@ def get_timestamp() -> str: return datetime.now().strftime("%y%m%d-%H%M%S") +class ConsoleFormatter(logging.Formatter): + """Custom formatter that prints logging.INFO messages without the level name. + + Source: https://stackoverflow.com/a/62488520 + """ + + def format(self, record): + if record.levelno == logging.INFO: + self._style._fmt = "%(message)s" + else: + self._style._fmt = "%(levelname)s: %(message)s" + return super().format(record) + + def setup_logger( logger_name: str, level: int = logging.INFO,