Skip to content

Commit

Permalink
optimize: log printing (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama authored Jun 22, 2024
1 parent 1430c95 commit 2eb97d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/ipynb/colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 12 additions & 6 deletions tools/logger/log.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 2eb97d2

Please sign in to comment.