Skip to content

Configuration & State

Immutable state management and environment detection.


LoggerConfigState

Python
LoggerConfigState(mode: str = 'terminal', highlight_syntax: bool = True, verbose: bool = False, deployed: bool = False, dd_trace_enabled: bool = False, color_enabled: bool = True, force_markup: bool = False, log_prefix: Optional[str] = None, show_thread_name: bool = False, level: LogLevel = LogLevel('INFO'))

Immutable configuration state - no mutations allowed.

is_compact_header_mode

Python
is_compact_header_mode: bool

Determines if headers should use compact formatting.

should_add_data_markers

Python
should_add_data_markers: bool

Determines if data markers should be added.

should_enable_dd_trace_logging

Python
should_enable_dd_trace_logging: bool

Determines if Datadog trace logging should be enabled.

should_highlight_data

Python
should_highlight_data: bool

Determines if data highlighting should be applied.

should_highlight_json_literals

Python
should_highlight_json_literals: bool

Determines if JSON literals should be highlighted.

should_show_env_prefix

Python
should_show_env_prefix: bool

Determines if environment prefix should be shown.

should_strip_ansi

Python
should_strip_ansi: bool

Determines if ANSI codes should be stripped.

should_suggest_exceptions

Python
should_suggest_exceptions: bool

Determines if exception suggestions should be provided.

should_use_json_formatter

Python
should_use_json_formatter: bool

Determines if JSON formatter should be used.

single_line_mode

Python
single_line_mode: bool

Determines if logs should be formatted as single lines.

should_format_message

Python
should_format_message(no_format: bool = False) -> bool

Determines if message formatting should be applied.

should_markup

Python
should_markup(force_override: bool = False) -> bool

Determines if markup/highlighting should be applied.

should_markup_with_override

Python
should_markup_with_override(force: bool = False) -> bool

Determines markup with potential force override.

should_use_color

Python
should_use_color(no_color: bool = False) -> bool

Determines if color should be used.

LoggerStateManager

Python
LoggerStateManager()

Single Source of Truth for: 1. Configuration state 2. ALL state-dependent services 3. State application logic

apply_temporary_state

Python
apply_temporary_state(temp_state: LoggerConfigState) -> LoggerConfigState

Apply temporary state and return old state for restoration.

configure

Python
configure(mode: Optional[Literal['terminal', 'json', 'compact']] = None, level: Optional[logLevels] = None, color_enabled: Optional[bool] = None, highlight_syntax: Optional[bool] = None, verbose: Optional[bool] = None, trace_enabled: Optional[bool] = None, deployment_mode: Optional[bool] = None, force_markup: Optional[bool] = None, suppress_autoconfig: Optional[bool] = False, prefix: object = _UNSET, show_thread_name: Optional[bool] = None) -> LoggerConfigState

Configure state and apply ALL side effects. No external callbacks needed - everything happens here.

create_temporary_state

Python
create_temporary_state(**overrides) -> LoggerConfigState

Create temporary state without applying it.

reinitialize

Python
reinitialize() -> LoggerConfigState

Reapply environment detection.

restore_state

Python
restore_state(previous_state: LoggerConfigState) -> None

Restore previous state from temporary context.

set_global_logger_manager

Python
set_global_logger_manager(internal_log_callback)

Called once during cLogger init to set up GlobalLoggerManager. Needs internal_log callback from cLogger since that's UI/logging, not state.

set_prefix

Python
set_prefix(prefix: Optional[str] = None) -> None

Set or clear the contextual log prefix shown in all output.

EnvironmentDetector

Detects deployment environment and provides environment-based config.

detect_deployment

Python
detect_deployment() -> Dict[str, Any]

Detect deployment environment and return config overrides.

get_env_metadata

Python
get_env_metadata() -> Dict[str, Optional[str]]

Extract environment metadata from system environment variables.

LogLevel

Defines LogLevel, an enumeration for logging levels.

The LogLevel class provides a specialized enumeration type for different logging levels, supporting standard, alias, and mapped values. It also provides convenient methods for resolving string and integer representations of log levels and for mapping custom aliases to specific log levels.

LogOptions

Python
LogOptions(opts=None, no_format=False, no_color=False, stack_info=False)

Configuration options for logging behavior and formatting.