1 utils.console.logging
utils.console.logging
Rich console with shared verbosity, debug state, and structured summaries.
This module provides Verbosity and the package-wide Console adapter for gated Rich output, progress reporting, and optional Lightning-log forwarding. It owns presentation state and routing only; callers retain responsibility for metric meaning, exception policy, and training control flow.
All instances share logging gates and the optional Lightning logger bridge; prefixes remain instance-local so concurrent components retain readable source context.
1.1 Classes
| Name | Description |
|---|---|
| Console | Console wrapper that centralises formatting and convenience helpers. |
| Verbosity | Ordered output gates shared by every Console instance. |
1.1.1 Console
utils.console.logging.Console(**kwargs)Console wrapper that centralises formatting and convenience helpers.
1.1.1.1 Attributes
| Name | Description |
|---|---|
| prefix | Instance-local ::-separated source context prepended to messages. |
| verbosity | Return the process-wide minimum level for informational output. |
| verbose | Report whether normal informational logging is currently enabled. |
| is_debug | Return the process-wide debug gate used by :meth:dbg. |
1.1.1.2 Methods
| Name | Description |
|---|---|
| with_prefix | Create a console instance with a prefixed context. |
| with_caller_prefix | Create a console with prefix inferred from the caller’s module and function. |
| from_callsite | Compatibility constructor mirroring the PRML VSLAM console API. |
| set_prefix | Set a custom prefix for all log messages. |
| unset_prefix | Remove this instance’s contextual prefix and return the console. |
| log | Emit an informational message when verbosity is enabled. |
| log_summary | Log a structured summary built from summarize. |
| warn | Emit a warning message and include a short caller stack. |
| error | Emit an error message and show the relevant caller stack. |
| plog | Pretty-print an object using the best available formatter. |
| dbg | Emit a debug message when debug mode is enabled. |
| dbg_summary | Emit a compact tensor-aware summary when debug logging is enabled. |
| set_verbosity | Set verbosity level (0=quiet, 1=normal, 2=verbose). |
| set_verbose | Backward-compatible alias for set_verbosity. |
| set_debug | Enable or disable debug logging while keeping verbose mode sensible. |
| set_timestamp_display | Toggle timestamps for subsequent log messages. |
| integrate_with_logger | Integrate all Console instances with PyTorch Lightning logger for WandB/TensorBoard logging. |
| update_global_step | Update the shared global step for all console instances. |
| capture_sink | Observe log lines in the current execution context. |
1.1.1.2.1 with_prefix
utils.console.logging.Console.with_prefix(*parts)Create a console instance with a prefixed context.
Enables builder-style chaining.
Usage:
console = Console.with_prefix(
self.__class__.__name__,
<name_of_the_current_method>
<further_parts>, # eg. stage, worker_idx...
)1.1.1.2.2 with_caller_prefix
utils.console.logging.Console.with_caller_prefix(*extra_parts, stack_depth=1)Create a console with prefix inferred from the caller’s module and function.
1.1.1.2.3 from_callsite
utils.console.logging.Console.from_callsite(*parts, stack_offset=0)Compatibility constructor mirroring the PRML VSLAM console API.
1.1.1.2.4 set_prefix
utils.console.logging.Console.set_prefix(*parts)Set a custom prefix for all log messages.
Enables builder-style chaining.
1.1.1.2.5 unset_prefix
utils.console.logging.Console.unset_prefix()Remove this instance’s contextual prefix and return the console.
1.1.1.2.6 log
utils.console.logging.Console.log(message)Emit an informational message when verbosity is enabled.
1.1.1.2.7 log_summary
utils.console.logging.Console.log_summary(label, value, *, include_stats=False)Log a structured summary built from summarize.
1.1.1.2.8 warn
utils.console.logging.Console.warn(message)Emit a warning message and include a short caller stack.
1.1.1.2.9 error
utils.console.logging.Console.error(message)Emit an error message and show the relevant caller stack.
1.1.1.2.10 plog
utils.console.logging.Console.plog(obj, **kwargs)Pretty-print an object using the best available formatter.
1.1.1.2.11 dbg
utils.console.logging.Console.dbg(message)Emit a debug message when debug mode is enabled.
1.1.1.2.12 dbg_summary
utils.console.logging.Console.dbg_summary(label, value, *, include_stats=False)Emit a compact tensor-aware summary when debug logging is enabled.
1.1.1.2.13 set_verbosity
utils.console.logging.Console.set_verbosity(level)Set verbosity level (0=quiet, 1=normal, 2=verbose).
1.1.1.2.14 set_verbose
utils.console.logging.Console.set_verbose(verbose)Backward-compatible alias for set_verbosity.
1.1.1.2.15 set_debug
utils.console.logging.Console.set_debug(is_debug)Enable or disable debug logging while keeping verbose mode sensible.
1.1.1.2.16 set_timestamp_display
utils.console.logging.Console.set_timestamp_display(show_timestamps)Toggle timestamps for subsequent log messages.
1.1.1.2.17 integrate_with_logger
utils.console.logging.Console.integrate_with_logger(logger, global_step=0)Integrate all Console instances with PyTorch Lightning logger for WandB/TensorBoard logging.
This is a class method that sets the shared logger state for all Console instances.
1.1.1.2.17.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| logger | Logger | PyTorch Lightning logger instance (e.g., WandbLogger, TensorBoardLogger). | required |
| global_step | int | Current training step for metric logging. | 0 |
1.1.1.2.17.2 Returns
| Name | Type | Description |
|---|---|---|
| type[Console] | Console class for method chaining. |
1.1.1.2.17.3 Example
# In your LightningModule.__init__
Console.integrate_with_logger(self.logger)
# In training_step
def training_step(self, batch, batch_idx):
Console.update_global_step(self.global_step)
console = Console.with_prefix("training")
console.log("Processing batch") # → Terminal + WandB!1.1.1.2.18 update_global_step
utils.console.logging.Console.update_global_step(global_step)Update the shared global step for all console instances.
1.1.1.2.19 capture_sink
utils.console.logging.Console.capture_sink(sink)Observe log lines in the current execution context.
Nested and concurrent contexts remain isolated. The previous observer is restored even when the observed operation raises.
1.1.2 Verbosity
utils.console.logging.Verbosity()Ordered output gates shared by every Console instance.
1.1.2.1 Methods
| Name | Description |
|---|---|
| from_any | Coerce booleans/ints/strings into a Verbosity level. |
1.1.2.1.1 from_any
utils.console.logging.Verbosity.from_any(value)Coerce booleans/ints/strings into a Verbosity level.