From cf18e0e4035cfc699531eadd2c38513848bc5a83 Mon Sep 17 00:00:00 2001 From: Vincent-Pierre BERGES Date: Tue, 30 Mar 2021 19:50:00 -0700 Subject: [PATCH] Fixing the GymWrapper Logging issue (#5201) (cherry picked from commit 8457c5bf87dcd943eb200a68735d48f84864448c) --- ml-agents-envs/mlagents_envs/logging_util.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ml-agents-envs/mlagents_envs/logging_util.py b/ml-agents-envs/mlagents_envs/logging_util.py index b768fc28ca..aab322c91c 100644 --- a/ml-agents-envs/mlagents_envs/logging_util.py +++ b/ml-agents-envs/mlagents_envs/logging_util.py @@ -1,4 +1,5 @@ import logging # noqa I251 +import sys CRITICAL = logging.CRITICAL FATAL = logging.FATAL @@ -20,11 +21,15 @@ def get_logger(name: str) -> logging.Logger: specified by set_log_level() """ logger = logging.getLogger(name=name) - # If we've already set the log level, make sure new loggers use it if _log_level != NOTSET: logger.setLevel(_log_level) + handler = logging.StreamHandler(stream=sys.stdout) + formatter = logging.Formatter(fmt=LOG_FORMAT, datefmt=DATE_FORMAT) + handler.setFormatter(formatter) + logger.addHandler(handler) + # Keep track of this logger so that we can change the log level later _loggers.add(logger) return logger @@ -37,10 +42,5 @@ def set_log_level(log_level: int) -> None: global _log_level _log_level = log_level - # Configure the log format. - # In theory, this would be sufficient, but if another library calls logging.basicConfig - # first, it doesn't have any effect. - logging.basicConfig(level=_log_level, format=LOG_FORMAT, datefmt=DATE_FORMAT) - for logger in _loggers: logger.setLevel(log_level)