Skip to content

Formatters

Output formatting for different modes and environments.


JSONLogFormatter

Python
JSONLogFormatter(env_metadata: Dict[str, Optional[str]], forced_color: bool, highlight_func: Callable[[str], str], traced: bool = False, deployed: bool = False)

Datadog-friendly JSON formatter that preserves existing structure and features.

Top-level fields (for Datadog correlation & triad): - service, env, version - dd.trace_id, dd.span_id

Preserved blocks: - source: module/function/line (unchanged) - log_info: logger/timestamp (unchanged) - context: harvested hints (unchanged) - exception: formatted tracebacks (unchanged)

Parameters

env_metadata : Dict[str, Optional[str]] Expected keys: env, project (service), project_version. forced_color : bool If True and not deployed, apply highlight function to the JSON string. highlight_func : Callable[[str], str] Function that colorizes the JSON string for terminals. traced : bool Kept for compatibility; IDs come from a filter, but we still surface them. deployed : bool If True, emit single-line compact JSON (for log routers).

CustomFormatter

Python
CustomFormatter(fmt: str, datefmt: Optional[str], presets: ColorPresets)

FileLogFormatter

Python
FileLogFormatter(base_formatter: Formatter)

FormatterFactory

Python
FormatterFactory(color_service: ColorService)

Creates appropriate formatters based on configuration state.

This factory encapsulates all the complex formatter creation logic that was previously scattered throughout cLogger.

create_formatter

Python
create_formatter(level: logLevels, config_state, env_metadata: Dict, global_stream_configured: bool = False, no_format: bool = False, no_color: bool = False) -> logging.Formatter

Create appropriate formatter based on level and configuration.

This replaces the complex __get_formatter method from cLogger.