fallback to basic logging if rich is not installed

This commit is contained in:
Kohya S
2024-02-04 18:28:54 +09:00
parent 5f6bf29e52
commit 6279b33736

View File

@@ -1,4 +1,5 @@
import logging import logging
import sys
import threading import threading
from typing import * from typing import *
@@ -11,9 +12,15 @@ def setup_logging(log_level=logging.INFO):
if logging.root.handlers: # Already configured if logging.root.handlers: # Already configured
return return
try:
from rich.logging import RichHandler from rich.logging import RichHandler
handler = RichHandler() handler = RichHandler()
except ImportError:
print("rich is not installed, using basic logging")
handler = logging.StreamHandler(sys.stdout) # same as print
handler.propagate = False
formatter = logging.Formatter( formatter = logging.Formatter(
fmt="%(message)s", fmt="%(message)s",
datefmt="%Y-%m-%d %H:%M:%S", datefmt="%Y-%m-%d %H:%M:%S",