Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 🔨 ] Fixing the GymWrapper Logging issue #5201

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)