Skip to content

Commit

Permalink
Fixing the GymWrapper Logging issue (#5201)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentpierre authored Mar 31, 2021
1 parent 2ca6a87 commit 8457c5b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ml-agents-envs/mlagents_envs/logging_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging # noqa I251
import sys

CRITICAL = logging.CRITICAL
FATAL = logging.FATAL
Expand All @@ -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
Expand All @@ -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)

0 comments on commit 8457c5b

Please sign in to comment.