Class Logger
- Namespace
- Gym
- Assembly
- Gym.dll
Where Gym's envs and wrappers report misuse and oddities without stopping: each message is issued through
Warnings as Python's warnings.warn would, with the WARN: /ERROR: prefix wrapped
in ANSI colour codes, so the text reads, and compares, exactly like Gymnasium's.
public static class Logger
- Inheritance
-
Logger
- Inherited Members
Remarks
A warning never throws and is shown once per call site (Python's default filter), so an env that warns on every misuse prints one line per process, not one per step. Tests observe warnings with Catch().
Python's msg % args formatting is left to the caller: C# callers pass the finished message (interpolated),
which is the same text for Gymnasium's call sites, none of which contains a % directive without arguments.
The call site is the direct caller (CallerFilePathAttribute/CallerLineNumberAttribute),
which is what stacklevel=2 selects for warn and deprecation; error's
stacklevel=3 would name the caller's caller, a difference that only changes which repeats are merged.
Reference: gymnasium/logger.py and gymnasium/utils/colorize.py.
Fields
ERROR
The level of Error(string, string, int), Python's logger.ERROR.
public const int ERROR = 40
Field Value
WARN
The level of Warn(string, WarningCategory, string, int) and Deprecation(string, string, int), Python's logger.WARN.
public const int WARN = 30
Field Value
Properties
MinLevel
The least severe level that is issued, Python's module global logger.min_level (30): raise it to
ERROR to silence warnings, or above to silence errors too. Process-wide, like the Python global.
public static int MinLevel { get; set; }
Property Value
Methods
Colorize(string, string, bool, bool)
Wraps text in the ANSI escape sequence of color,
"\x1b[{attrs}m{text}\x1b[0m". The escape codes become part of the text, so terminals colour it and
captured warnings compare byte for byte with Gymnasium's; a sink that does not interpret ANSI shows them raw.
public static string Colorize(string text, string color, bool bold = false, bool highlight = false)
Parameters
textstringThe text to colour.
colorstringgray, red, green, yellow, blue, magenta, cyan, white or crimson.
boldboolAdds the bold attribute (
1).highlightboolUses the background colour (the number plus 10).
Returns
- string
The coloured text.
Remarks
Reference: gymnasium/utils/colorize.py.
Exceptions
- KeyNotFoundException
Thrown for an unknown colour name, as Python's dict lookup raises
KeyError.
Deprecation(string, string, int)
Warns that an API is going away: Warn(string, WarningCategory, string, int) with DeprecationWarning, which
is shown once per message however many call sites issue it (the once filter Gymnasium installs).
public static void Deprecation(string msg, string callerFilePath = "", int callerLineNumber = 0)
Parameters
msgstringThe finished message.
callerFilePathstringFilled in by the compiler: the call site's file.
callerLineNumberintFilled in by the compiler: the call site's line.
Remarks
Reference: gymnasium/logger.py.
Exceptions
- ArgumentNullException
Thrown when
msgis null.
Error(string, string, int)
Reports a serious problem without stopping the caller: issues colorize("ERROR: " + msg, "red") as a user
warning when MinLevel allows it. Despite the name it does not throw; the caller decides what to do.
public static void Error(string msg, string callerFilePath = "", int callerLineNumber = 0)
Parameters
msgstringThe finished message.
callerFilePathstringFilled in by the compiler: the call site's file.
callerLineNumberintFilled in by the compiler: the call site's line.
Remarks
Reference: gymnasium/logger.py.
Exceptions
- ArgumentNullException
Thrown when
msgis null.
Warn(string, WarningCategory, string, int)
Issues colorize("WARN: " + msg, "yellow") as a warning of category, attributed to the
calling line, when MinLevel allows it. The caller carries on: a warning never throws, and the
filters of Warnings drop repeats.
public static void Warn(string msg, WarningCategory category = WarningCategory.UserWarning, string callerFilePath = "", int callerLineNumber = 0)
Parameters
msgstringThe finished message (Python's
msg % argsalready applied).categoryWarningCategoryThe warning class; Python's
Nonemeans UserWarning.callerFilePathstringFilled in by the compiler: the call site's file.
callerLineNumberintFilled in by the compiler: the call site's line.
Remarks
Reference: gymnasium/logger.py.
Exceptions
- ArgumentNullException
Thrown when
msgis null.