From 2eb97d212f5e226dc6252bb52e26fed377457054 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: Sun, 23 Jun 2024 01:27:49 +0900 Subject: [PATCH] optimize: log printing (#411) --- examples/ipynb/colab.ipynb | 2 +- tools/logger/log.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/ipynb/colab.ipynb b/examples/ipynb/colab.ipynb index 79b243cd7..ffd4aa4af 100644 --- a/examples/ipynb/colab.ipynb +++ b/examples/ipynb/colab.ipynb @@ -18,7 +18,7 @@ "outputs": [], "source": [ "!cd /content\n", - "!rm -rf /content/ChatTTS\n", + "!rm -rf sample_data ChatTTS\n", "!git clone https://github.com/2noise/ChatTTS.git\n", "!pip install -r /content/ChatTTS/requirements.txt\n", "!ldconfig /usr/lib64-nvidia" diff --git a/tools/logger/log.py b/tools/logger/log.py index 00cd7b008..ce08989bd 100644 --- a/tools/logger/log.py +++ b/tools/logger/log.py @@ -1,7 +1,6 @@ import platform import logging from datetime import datetime, timezone -from functools import lru_cache logging.getLogger("numba").setLevel(logging.WARNING) logging.getLogger("httpx").setLevel(logging.WARNING) @@ -45,14 +44,21 @@ def format(self, record: logging.LogRecord): logstr += log_level_msg_str.get(record.levelno, record.levelname) if self.color: logstr += colorReset - logstr += f"] {str(record.name)} | {str(record.msg)%record.args}" + fn = record.filename.removesuffix(".py") + logstr += f"] {str(record.name)} | {fn} | {str(record.msg)%record.args}" return logstr -@lru_cache(maxsize=None) +for h in logging.root.handlers: + h.setFormatter(Formatter()) + def get_logger(name: str, lv = logging.INFO): logger = logging.getLogger(name) - syslog = logging.StreamHandler() - syslog.setFormatter(Formatter()) logger.setLevel(lv) - logger.addHandler(syslog) + if not logger.hasHandlers(): + syslog = logging.StreamHandler() + syslog.setFormatter(Formatter()) + logger.addHandler(syslog) + else: + for h in logger.handlers: + h.setFormatter(Formatter()) return logger