From 0539966b089256664eca5d6f0e480977a6f7d95b Mon Sep 17 00:00:00 2001 From: LielinJiang Date: Wed, 29 Apr 2020 12:30:11 +0000 Subject: [PATCH] fix logger in python2 --- hapi/logger.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hapi/logger.py b/hapi/logger.py index 5431363..8b92390 100644 --- a/hapi/logger.py +++ b/hapi/logger.py @@ -36,13 +36,13 @@ def setup_logger(output=None, name="hapi", log_level=logging.INFO): logger.propagate = False logger.setLevel(log_level) + format_str = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' # stdout logging: only local rank==0 local_rank = ParallelEnv().local_rank - if local_rank == 0 and not logger.hasHandlers(): + if local_rank == 0 and len(logger.handlers) == 0: ch = logging.StreamHandler(stream=sys.stdout) ch.setLevel(log_level) - format_str = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ch.setFormatter(logging.Formatter(format_str)) logger.addHandler(ch) @@ -52,6 +52,7 @@ def setup_logger(output=None, name="hapi", log_level=logging.INFO): filename = output else: filename = os.path.join(output, "log.txt") + if local_rank > 0: filename = filename + ".rank{}".format(local_rank) -- GitLab