espnet3.utils.logging_utils.log_component
Less than 1 minute
espnet3.utils.logging_utils.log_component
espnet3.utils.logging_utils.log_component(logger: Logger, kind: str, label: str, obj, max_depth: int) → None
Log a component instance with class info, repr, and attributes.
Description: : Emits a structured log block for a single object. The block includes a class line, a representation line, and a recursive attribute dump up to the specified depth.
- Parameters:
- logger (logging.Logger) – Logger used to emit messages.
- kind (str) – Label prefix for the entry (e.g., “Component”, “Env”).
- label (str) – Human-readable label identifying the entry.
- obj – Object instance to log. If None, the function returns early.
- max_depth (int) – Maximum depth for recursive attribute dumping.
- Raises:None –
- Returns: None
Example
```python from espnet3.utils.logging_utils import log_component
Custom class instance.
class CustomThing:
def __init__(self, name: str, value: int): : self.name = name self.value = value
log_component(logger, “Custom”, “example”, CustomThing(“demo”, 7))
```Example log output:
``` Custom[example] class: my_module.CustomThing Custom[example]: <my_module.CustomThing object at …>
name: ‘demo’ value: 7
```Notes
- The logger uses stacklevel=2 so log lines point at the caller.
- Attribute dumping uses build_qualified_name for readable class names.
- Set max_depth to 0 to log only the class and repr lines.
