Skip to content

Commit 8457c5b

Browse files
Fixing the GymWrapper Logging issue (#5201)
1 parent 2ca6a87 commit 8457c5b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ml-agents-envs/mlagents_envs/logging_util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging # noqa I251
2+
import sys
23

34
CRITICAL = logging.CRITICAL
45
FATAL = logging.FATAL
@@ -20,11 +21,15 @@ def get_logger(name: str) -> logging.Logger:
2021
specified by set_log_level()
2122
"""
2223
logger = logging.getLogger(name=name)
23-
2424
# If we've already set the log level, make sure new loggers use it
2525
if _log_level != NOTSET:
2626
logger.setLevel(_log_level)
2727

28+
handler = logging.StreamHandler(stream=sys.stdout)
29+
formatter = logging.Formatter(fmt=LOG_FORMAT, datefmt=DATE_FORMAT)
30+
handler.setFormatter(formatter)
31+
logger.addHandler(handler)
32+
2833
# Keep track of this logger so that we can change the log level later
2934
_loggers.add(logger)
3035
return logger
@@ -37,10 +42,5 @@ def set_log_level(log_level: int) -> None:
3742
global _log_level
3843
_log_level = log_level
3944

40-
# Configure the log format.
41-
# In theory, this would be sufficient, but if another library calls logging.basicConfig
42-
# first, it doesn't have any effect.
43-
logging.basicConfig(level=_log_level, format=LOG_FORMAT, datefmt=DATE_FORMAT)
44-
4545
for logger in _loggers:
4646
logger.setLevel(log_level)

0 commit comments

Comments
 (0)