Logger¶
Module: polygraphy.logger
- class LogMode(value)[source]¶
Bases:
IntEnum
Specifies how messages should be logged.
- EACH = 0¶
Log the message each time
- ONCE = 1¶
Log the message only once. The same message will not be logged again.
- class SeverityTrie(severity_dict)[source]¶
Bases:
object
A trie that represents per-path logging verbosities.
- class Logger(severity=20, colors=True, letter=True, timestamp=False, line_info=False)[source]¶
Bases:
object
Global logging interface. Do not construct a logger manually. Instead, use
G_LOGGER
, the global logger.- Parameters:
severity (Union[int, Dict[str, int]]) – Severity below which messages will be ignored. This can be specified on a per-submodule/file basis by providing a dictionary of paths to logging severities. In this case, use the
""
to indicate the default severity. Paths should be relative to the polygraphy/ directory. For example, polygraphy/backend can be specified with just backend/. For example:{"": G_LOGGER.INFO, "backend/trt": G_LOGGER.VERBOSE}
This is converted to aSeverityTrie
on assignment. Defaults to G_LOGGER.INFO.colors (bool) – Whether to use colored output. Defaults to True.
letter (bool) – Whether to prepend each logging message with a letter indicating it’s severity. Defaults to True.
timestamp (bool) – Whether to include a timestamp in the logging output. Defaults to False.
line_info (bool) – Whether to include file and line number information in the logging output. Defaults to False.
- ULTRA_VERBOSE = -20¶
Enable unreasonably verbose messages and above
- SUPER_VERBOSE = -10¶
Enable extremely verbose messages and above
- EXTRA_VERBOSE = 0¶
Enable extra verbose messages and above
- VERBOSE = 10¶
Enable verbose messages and above
- INFO = 20¶
Enable informative messages and above
- START = 22¶
Enable messages indicating when a task is started and above
- FINISH = 28¶
Enable messages indicating when a task is finished and above
- WARNING = 30¶
Enable only warning messages and above
- ERROR = 40¶
Enable only error messages and above
- CRITICAL = 50¶
Enable only critical/fatal error messages and above
- property log_file¶
Path to a log file to write logging output from Polygraphy. This will not include logging messages from libraries used by Polygraphy, like TensorRT or ONNX-Runtime.
- property module_severity¶
Severity below which messages will be ignored. This can be specified on a per-submodule/file basis by providing a dictionary of paths to logging severities. In this case, use the
""
to indicate the default severity. Paths should be relative to the polygraphy/ directory. For example, polygraphy/backend can be specified with just backend/. For example:{"": G_LOGGER.INFO, "backend/trt": G_LOGGER.VERBOSE}
This is converted to aSeverityTrie
on assignment. Defaults to G_LOGGER.INFO.
- module_path(path)[source]¶
Converts a given path to a path relative to the Polygraphy root module. If the path is not part of the Polygraphy module, returns a path relative to the common prefix.
- Parameters:
path (str) – The path
- Returns:
The path relative to the Polygraphy root module or common prefix.
- Return type:
str
- register_callback(callback)[source]¶
Registers a callback with the logger, which will be invoked when the logging severity is modified. The callback is guaranteed to be called at least once in the register_callback function.
- Parameters:
callback (Callable(SeverityTrie)) – A callback that accepts the current logger severity trie.
- indent(level=1)[source]¶
Returns a context manager that indents all strings logged by the specified amount.
- Parameters:
level (int) – The indentation level
- verbosity(severity=50)[source]¶
Returns a context manager that temporarily changes the severity of the logger for its duration.
- Parameters:
severity (Union[int, Dict[str, int]]) – Severity below which messages will be ignored. This can be specified on a per-submodule/file basis by providing a dictionary of paths to logging severities. In this case, use the
""
to indicate the default severity. For example:{"": G_LOGGER.INFO, "backend/trt": G_LOGGER.VERBOSE}
Defaults to Logger.CRITICAL, which will suppress all messages.
- log(message, severity, mode=LogMode.EACH, stack_depth=2, error_ok=False)[source]¶
Logs a message to stdout.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
severity (int) – The severity with which to log this message. If the severity is less than the logger’s current severity, the message is suppressed. Provided callables will not be called in that case.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
stack_depth (int) – The stack depth to use to determine file and line information. Defaults to 2.
error_ok (bool) – Whether to suppress errors encountered while logging. When this is True, in the event of an error, the message will not be logged, but the logger will recover and resume execution. When False, the logger will re-raise the exception.
- ultra_verbose(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with ULTRA_VERBOSE severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- super_verbose(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with SUPER_VERBOSE severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- extra_verbose(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with EXTRA_VERBOSE severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- verbose(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with VERBOSE severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- info(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with INFO severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- start(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with START severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- finish(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with FINISH severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- warning(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with WARNING severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- error(message, mode=LogMode.EACH)[source]¶
Logs a message to stdout with ERROR severity.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
mode (LogMode) – Controls how the message is logged. See LogMode for details.
- critical(message, ExceptionType=None)[source]¶
Logs a message to stdout with CRITICAL severity and raises an exception.
- Parameters:
message (Union[str, Callable() -> str]) – A string or callable which returns a string of the message to log.
ExceptionType (type) – The type of exception to raise. Defaults to PolygraphyException.
- Raises:
ExceptionType –
- G_LOGGER = <polygraphy.logger.logger.Logger object>¶
The global logger. Use this instead of constructing a logger