nemo_evaluator.logging.utils#

Logging configuration module for nemo-evaluator.

This module provides a centralized logging configuration using structlog that outputs to both stderr and a log file. All modules should import and use the logger from this module to ensure consistent logging behavior across the application.

Module Contents#

Classes#

MainConsoleRenderer

Custom console renderer for [L TIMESTAMP] message with color by level.

Functions#

configure_logging

Configure logging with a custom log directory.

custom_timestamper

Add ISO UTC timestamp with milliseconds to event_dict[‘timestamp’].

get_logger

Get a configured structlog logger.

Data#

API#

class nemo_evaluator.logging.utils.MainConsoleRenderer(colors: bool = True)[source]#

Custom console renderer for [L TIMESTAMP] message with color by level.

Initialization

LEVEL_MAP#

None

RESET#

‘\x1b[0m’

nemo_evaluator.logging.utils.configure_logging(log_dir: str = None) None[source]#

Configure logging with a custom log directory.

Args: log_dir: Custom log directory path. If None, uses NEMO_EVALUATOR_LOG_DIR environment variable. If neither is set, only console logging is configured.

nemo_evaluator.logging.utils.custom_timestamper(_, __, event_dict)[source]#

Add ISO UTC timestamp with milliseconds to event_dict[‘timestamp’].

nemo_evaluator.logging.utils.get_logger(name: str = None) structlog.BoundLogger[source]#

Get a configured structlog logger.

nemo_evaluator.logging.utils.logger#

‘get_logger(…)’

LOGGING POLICY:#

All logging in this project MUST go through this module. This is enforced by a pre-commit hook that checks for violations.

DO NOT:

  • import structlog directly

  • import logging directly

  • call structlog.get_logger() directly

  • call logging.getLogger() directly

DO:

  • from nemo_evaluator.common.logging_utils import logger

  • from nemo_evaluator.common.logging_utils import get_logger

Examples: # Correct from nemo_evaluator.common.logging_utils import logger logger.info(“User logged in”, user_id=”12345”)

# Incorrect
import structlog
logger = structlog.get_logger()
logger.info("User logged in")