Skip to content

Commit

Permalink
update log initialization without rich
Browse files Browse the repository at this point in the history
  • Loading branch information
kohya-ss committed Feb 8, 2024
1 parent efd3b58 commit 9b8ea12
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ def setup_logging(args=None, log_level=None, reset=False):
else:
return

# log_level can be set by the caller or by the args, the caller has priority. If not set, use INFO
if log_level is None and args is not None:
log_level = args.console_log_level
if log_level is None:
log_level = "INFO"
log_level = getattr(logging, log_level)

msg_init = None
if args is not None and args.console_log_file:
handler = logging.FileHandler(args.console_log_file, mode="w")
else:
Expand All @@ -50,7 +52,8 @@ def setup_logging(args=None, log_level=None, reset=False):

handler = RichHandler()
except ImportError:
print("rich is not installed, using basic logging")
# print("rich is not installed, using basic logging")
msg_init = "rich is not installed, using basic logging"

if handler is None:
handler = logging.StreamHandler(sys.stdout) # same as print
Expand All @@ -63,3 +66,7 @@ def setup_logging(args=None, log_level=None, reset=False):
handler.setFormatter(formatter)
logging.root.setLevel(log_level)
logging.root.addHandler(handler)

if msg_init is not None:
logger = logging.getLogger(__name__)
logger.info(msg_init)

0 comments on commit 9b8ea12

Please sign in to comment.