Logger¶
Module: polygraphy.logger
- class LogMode(*values)¶
Bases:
IntEnumSpecifies how messages should be logged.
- class Logger(severity=20, colors=True, letter=True, timestamp=False, line_info=False)¶
Bases:
objectGlobal 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 aSeverityTrieon 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.
- critical(message, ExceptionType=None)¶
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 –
- error(message, mode=LogMode.EACH)¶
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.
- extra_verbose(message, mode=LogMode.EACH)¶
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.
- finish(message, mode=LogMode.EACH)¶
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.
- indent(level=1)¶
Returns a context manager that indents all strings logged by the specified amount.
- Parameters:
level (int) – The indentation level
- info(message, mode=LogMode.EACH)¶
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.
- log(message, severity, mode=LogMode.EACH, stack_depth=2, error_ok=False)¶
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.
- log_exception(func)¶
Decorator that causes exceptions in a function to be logged. This is useful in cases where the exception is caught by a caller, but should still be logged.
- module_path(path)¶
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)¶
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.
- start(message, mode=LogMode.EACH)¶
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.
- super_verbose(message, mode=LogMode.EACH)¶
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.
- ultra_verbose(message, mode=LogMode.EACH)¶
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.
- verbose(message, mode=LogMode.EACH)¶
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.
- verbosity(severity=50)¶
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.