"""Logging module with context-aware logger selection.

Mirrors t_obs.logs interface for easy migration.
"""

import logging
from typing import Optional

from thoughtful.supervisor.telemetry.config import get_service_name


def get_logger(name: Optional[str] = None) -> logging.Logger:
    """Get a namespaced logger for the service.

    When telemetry is initialized with logging enabled, logs will be
    automatically exported to your OTLP endpoint with trace context.

    Args:
        name: Optional namespace suffix. Results in "{service}.{name}" logger.

    Returns:
        Python logging.Logger instance.

    Example:
        from thoughtful.supervisor.telemetry.logs import get_logger

        logger = get_logger("my_module")
        logger.info("Processing record", extra={"record_id": "123"})
    """
    service_name = get_service_name()
    logger_name = service_name if name is None else f"{service_name}.{name}"
    return logging.getLogger(logger_name)


__all__ = ["get_logger"]
