rlightning.utils.logger.logger¶
- class rlightning.utils.logger.logger.MetricsLogger(logger: Logger)[source]¶
Bases:
objectA logger utility for recording metrics.
- log_metric(payload: Dict[str, Any], level: int = 20, step: int = None, prefix: str = None) None[source]¶
Log a metric payload with automatic prefixing.
The payload is formatted into a JSON string with a “[METRIC]” prefix. Metric names are automatically prefixed with worker/actor identifiers.
- Parameters:
payload – Dictionary containing metric data.
level – The logging level to use for the metric (default: INFO).
step – Optional global/local step for metric consumers.
prefix – Optional override for metric key prefix.
- rlightning.utils.logger.logger.get_logger(name: str) Logger[source]¶
Get a logging logger for the given name.
- rlightning.utils.logger.logger.get_metrics_logger(name: str | None = None) MetricsLogger[source]¶
Get a cached MetricsLogger instance for the given name.
This function acts as a factory for MetricsLogger instances. It wraps the standard logging.getLogger() to ensure that loggers are uniquely named and re-used.
It’s recommended to call this from your modules with __name__, like so: logger = get_metrics_logger(__name__)
- Parameters:
name – Name for the logger. If None, an application-wide ‘metrics’ logger is returned.
- Returns:
A MetricsLogger instance.
- rlightning.utils.logger.logger.is_ray_worker() bool[source]¶
Check if the current context is a Ray worker process.
- rlightning.utils.logger.logger.log_metric(payload: Dict[str, Any], level: int = 20, step: int = None, prefix: str = None) None[source]¶
Log a metric payload using the default metrics logger.
- Parameters:
payload – Metrics payload to log.
level – Logging level.
step – Optional step index.
prefix – Optional metric name prefix.