Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Sdv dev SDV CSVFormatter Get SDV Logger

From Leeroopedia
Revision as of 13:49, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Sdv_dev_SDV_CSVFormatter_Get_SDV_Logger.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Logging, Observability
Last Updated 2026-02-14 19:00 GMT

Overview

Concrete tool for CSV-formatted logging and configurable logger retrieval provided by the SDV library.

Description

The sdv.logging.logger module provides two key components: the CSVFormatter class and the get_sdv_logger function. CSVFormatter is a custom logging.Formatter that writes log records as CSV rows with predefined headers (LEVEL, EVENT, TIMESTAMP, SYNTHESIZER CLASS NAME, SYNTHESIZER ID, TOTAL NUMBER OF TABLES, TOTAL NUMBER OF ROWS, TOTAL NUMBER OF COLUMNS). The get_sdv_logger function creates and caches logger instances based on the SDV logger configuration (loaded from sdv_logger_config.yml), supporting file-based and stream-based handlers with CSV or standard formatting. It is decorated with safely_return_logger to fall back to a NullHandler logger on PermissionError.

Usage

Import get_sdv_logger to obtain a configured logger instance for use within SDV synthesizer classes. The CSVFormatter is used internally when the logger config specifies CSV formatting. End users typically interact with logging through the log files produced at the configured output path.

Code Reference

Source Location

Signature

class CSVFormatter(logging.Formatter):
    """Logging formatter to convert to CSV."""

    def __init__(self, filename=None): ...
    def format(self, record) -> str: ...


def safely_return_logger(func):
    """Decorator to safely return a logger, falling back to NullHandler on PermissionError."""
    ...


@lru_cache()
@safely_return_logger
def get_sdv_logger(logger_name: str) -> logging.Logger:
    """Get a logger instance with the specified name and configuration."""
    ...

Import

from sdv.logging.logger import get_sdv_logger, CSVFormatter

I/O Contract

Inputs (get_sdv_logger)

Name Type Required Description
logger_name str Yes Name of the logger to retrieve or create (e.g. 'SingleTableSynthesizer')

Outputs (get_sdv_logger)

Name Type Description
logger logging.Logger Configured logger instance with appropriate handlers and formatters

Inputs (CSVFormatter.__init__)

Name Type Required Description
filename str No Path to logfile; if file does not exist, CSV header is written

Usage Examples

Getting a Logger

from sdv.logging.logger import get_sdv_logger

# Get a configured logger for synthesizer events
logger = get_sdv_logger('SingleTableSynthesizer')

# Log a synthesizer event
logger.info({
    'EVENT': 'Fit',
    'TIMESTAMP': '2024-01-15 10:30:00',
    'SYNTHESIZER CLASS NAME': 'GaussianCopulaSynthesizer',
    'SYNTHESIZER ID': 'abc123',
    'TOTAL NUMBER OF TABLES': 1,
    'TOTAL NUMBER OF ROWS': 1000,
    'TOTAL NUMBER OF COLUMNS': 5,
})

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment