From cae0fec15b9b8857022edc7bbd136145acea4b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:39:50 +0900 Subject: [PATCH] fix(colab): color log printing (#430) --- examples/ipynb/colab.ipynb | 2 +- tools/logger/log.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/ipynb/colab.ipynb b/examples/ipynb/colab.ipynb index 0ef9f581c..416f42e73 100644 --- a/examples/ipynb/colab.ipynb +++ b/examples/ipynb/colab.ipynb @@ -72,7 +72,7 @@ }, "outputs": [], "source": [ - "logger = get_logger(\"ChatTTS\", remove_exist=True)\n", + "logger = get_logger(\"ChatTTS\", format_root=True)\n", "chat = ChatTTS.Chat(logger)\n", "\n", "# try to load normalizer\n", diff --git a/tools/logger/log.py b/tools/logger/log.py index 4400116d7..603a7d5a2 100644 --- a/tools/logger/log.py +++ b/tools/logger/log.py @@ -51,7 +51,7 @@ def format(self, record: logging.LogRecord): return logstr -def get_logger(name: str, lv = logging.INFO, remove_exist=False): +def get_logger(name: str, lv = logging.INFO, remove_exist=False, format_root=False): logger = logging.getLogger(name) logger.setLevel(lv) if remove_exist and logger.hasHandlers(): @@ -63,4 +63,7 @@ def get_logger(name: str, lv = logging.INFO, remove_exist=False): else: for h in logger.handlers: h.setFormatter(Formatter()) + if format_root: + for h in logger.root.handlers: + h.setFormatter(Formatter()) return logger