Skip to content

Logging

liblaf.cherries.plugins.logging

Classes:

  • Logging –

    Initialize Python logging and mirror metrics to the run log.

Attributes:

logger module-attribute

logger: Logger = logging.getLogger(__name__)

Logging

Bases: Plugin


              flowchart TD
              liblaf.cherries.plugins.logging.Logging[Logging]
              liblaf.cherries.core.plugin._plugin.Plugin[Plugin]

                              liblaf.cherries.core.plugin._plugin.Plugin --> liblaf.cherries.plugins.logging.Logging
                


              click liblaf.cherries.plugins.logging.Logging href "" "liblaf.cherries.plugins.logging.Logging"
              click liblaf.cherries.core.plugin._plugin.Plugin href "" "liblaf.cherries.core.plugin._plugin.Plugin"
            

Initialize Python logging and mirror metrics to the run log.

Attributes:

Parameters:

  • name (PluginName, default: <dynamic> ) –
  • run (Run) –

Methods:

  • log_metric –

    Write one metric to the Python logger.

  • log_metrics –

    Write multiple metrics to the Python logger.

  • start –

    Initialize liblaf.logging for the run log file.

log_file cached property

log_file: Path

Default log file below the run working directory.

name class-attribute instance-attribute

name: PluginName = attrs.field(
    default=attrs.Factory(_default_name, takes_self=True),
    kw_only=True,
)

run class-attribute instance-attribute

run: Run = attrs.field(repr=False)

log_metric

log_metric(
    name: str, value: float, *, step: int, time: datetime
) -> None

Write one metric to the Python logger.

Source code in src/liblaf/cherries/plugins/logging.py
@core.impl
def log_metric(self, name: str, value: float, *, step: int, time: datetime) -> None:
    """Write one metric to the Python logger."""
    del time
    logger.info("step: %s, %s: %s", step, name, value)

log_metrics

log_metrics(
    metrics: Mapping[str, float],
    *,
    step: int,
    time: datetime,
) -> None

Write multiple metrics to the Python logger.

Source code in src/liblaf/cherries/plugins/logging.py
@core.impl
def log_metrics(
    self, metrics: Mapping[str, float], *, step: int, time: datetime
) -> None:
    """Write multiple metrics to the Python logger."""
    del time
    logger.info("step: %s, %s", step, metrics)

start

start(*args, **kwargs) -> None

Initialize liblaf.logging for the run log file.

Source code in src/liblaf/cherries/plugins/logging.py
@core.impl(before=("Local",))
def start(self, *args, **kwargs) -> None:
    """Initialize `liblaf.logging` for the run log file."""
    del args, kwargs
    liblaf.logging.init(file=self.log_file, force=True)