Files
Gymnasium/gym/configuration.py

44 lines
1.4 KiB
Python
Raw Normal View History

2016-04-27 08:00:58 -07:00
import logging
import sys
logger = logging.getLogger(__name__)
root_logger = logging.getLogger()
2016-10-01 19:24:50 -07:00
2016-10-01 19:35:41 -07:00
# Should be "gym", but we'll support people doing somewhat crazy
# things.
package_name = '.'.join(__name__.split('.')[:-1])
gym_logger = logging.getLogger(package_name)
2016-10-01 19:24:50 -07:00
# Should be modified only by official Gym plugins. This is an
# unsupported API and may be removed in future versions.
2016-10-01 19:35:41 -07:00
_extra_loggers = [gym_logger]
2016-04-27 08:00:58 -07:00
# Set up the default handler
formatter = logging.Formatter('[%(asctime)s] %(message)s')
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(formatter)
# We need to take in the gym logger explicitly since this is called
# at initialization time.
2016-10-01 21:59:08 -07:00
def logger_setup(_=None):
# This used to take in an argument; we still take an (ignored)
# argument for compatibility.
2016-04-27 08:00:58 -07:00
root_logger.addHandler(handler)
2016-10-01 19:35:41 -07:00
for logger in _extra_loggers:
2016-10-01 19:24:50 -07:00
logger.setLevel(logging.INFO)
2016-04-27 08:00:58 -07:00
def undo_logger_setup():
"""Undoes the automatic logging setup done by OpenAI Gym. You should call
this function if you want to manually configure logging
yourself. Typical usage would involve putting something like the
following at the top of your script:
gym.undo_logger_setup()
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler(sys.stderr))
"""
root_logger.removeHandler(handler)
2016-10-01 19:35:41 -07:00
for logger in _extra_loggers:
2016-10-01 19:24:50 -07:00
logger.setLevel(logging.NOTSET)