2022-05-10 15:35:45 +01:00
|
|
|
"""Set of functions for logging messages."""
|
2024-06-10 17:07:47 +01:00
|
|
|
|
2018-11-29 02:27:27 +01:00
|
|
|
import warnings
|
|
|
|
|
2022-09-08 10:10:07 +01:00
|
|
|
from gymnasium.utils import colorize
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
|
2022-12-04 22:24:02 +08:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
WARN = 30
|
|
|
|
ERROR = 40
|
|
|
|
|
2021-11-18 00:16:57 +01:00
|
|
|
min_level = 30
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
|
2021-07-29 02:26:34 +02:00
|
|
|
|
2022-09-05 10:35:56 -04:00
|
|
|
# Ensure DeprecationWarning to be displayed (#2685, #3059)
|
2022-09-08 10:10:07 +01:00
|
|
|
warnings.filterwarnings("once", "", DeprecationWarning, module=r"^gymnasium\.")
|
2022-03-11 17:46:21 -05:00
|
|
|
|
|
|
|
|
2021-11-18 00:16:57 +01:00
|
|
|
def warn(
|
|
|
|
msg: str,
|
|
|
|
*args: object,
|
2025-06-07 17:57:58 +01:00
|
|
|
category: type[Warning] | None = None,
|
2021-11-18 00:16:57 +01:00
|
|
|
stacklevel: int = 1,
|
|
|
|
):
|
2022-05-10 15:35:45 +01:00
|
|
|
"""Raises a warning to the user if the min_level <= WARN.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
msg: The message to warn the user
|
|
|
|
*args: Additional information to warn the user
|
|
|
|
category: The category of warning
|
|
|
|
stacklevel: The stack level to raise to
|
|
|
|
"""
|
2021-11-18 00:16:57 +01:00
|
|
|
if min_level <= WARN:
|
2021-10-02 08:36:02 +08:00
|
|
|
warnings.warn(
|
2021-11-14 14:50:40 +01:00
|
|
|
colorize(f"WARN: {msg % args}", "yellow"),
|
2021-10-02 08:36:02 +08:00
|
|
|
category=category,
|
|
|
|
stacklevel=stacklevel + 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-18 00:16:57 +01:00
|
|
|
def deprecation(msg: str, *args: object):
|
2022-05-10 15:35:45 +01:00
|
|
|
"""Logs a deprecation warning to users."""
|
2021-10-02 08:36:02 +08:00
|
|
|
warn(msg, *args, category=DeprecationWarning, stacklevel=2)
|
2021-07-29 02:26:34 +02:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
|
2021-11-18 00:16:57 +01:00
|
|
|
def error(msg: str, *args: object):
|
2022-05-10 15:35:45 +01:00
|
|
|
"""Logs an error message if min_level <= ERROR in red on the sys.stderr."""
|
2021-11-18 00:16:57 +01:00
|
|
|
if min_level <= ERROR:
|
2024-07-15 15:53:11 +01:00
|
|
|
warnings.warn(colorize(f"ERROR: {msg % args}", "red"), stacklevel=3)
|