forked from SWivid/F5-TTS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
31 lines (20 loc) · 922 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from pathlib import Path
from sys import stdout
from loguru import logger as _logger
from loguru._logger import Logger
from .logger import ERROR_LOG, INFO_LOG, LOG_FORMAT
LOGGER_ROOT = "logs"
LOGGER_LEVEL = "DEBUG"
def init_logger() -> Logger:
log_root = Path(LOGGER_ROOT)
if not log_root.exists():
log_root.mkdir(parents=True)
if not log_root.is_dir():
raise ValueError("LOG_ROOT is not a directory")
_logger.remove() # remove origin handler
_logger.add(stdout, colorize=True, enqueue=True, level=LOGGER_LEVEL, format=LOG_FORMAT)
_logger.add(log_root.joinpath(INFO_LOG), encoding="utf-8", rotation="10MB", enqueue=True, level="INFO", format=LOG_FORMAT)
_logger.add(log_root.joinpath(ERROR_LOG), encoding="utf-8", rotation="10MB", enqueue=True, level="ERROR", format=LOG_FORMAT)
_logger.info("Init logger successfully")
return _logger
logger = init_logger()