extended_data.logging.utils

Utility helpers for structured logging internals.

Module Contents

Functions

get_log_level

Converts a log level from string or integer to a logging level integer.

get_loggers

Retrieves all active loggers.

find_logger

Finds a logger by its name.

clear_existing_handlers

Removes all existing handlers from the logger.

sanitize_json_data

Sanitize data for JSON serialization using Extended Data core utilities.

add_labeled_json

Add labeled JSON data to the message.

add_unlabeled_json

Add unlabeled JSON data to the message.

add_json_data

Add JSON data to the log message.

API

extended_data.logging.utils.get_log_level(level: int | str) int

Converts a log level from string or integer to a logging level integer.

Args: level (int | str): The log level as a string or integer.

Returns: int: The corresponding logging level integer.

extended_data.logging.utils.get_loggers() list[logging.Logger]

Retrieves all active loggers.

Returns: list[logging.Logger]: A list of all active logger instances.

extended_data.logging.utils.find_logger(name: str) logging.Logger | None

Finds a logger by its name.

Args: name (str): The name of the logger to find.

Returns: logging.Logger | None: The logger instance if found, otherwise None.

extended_data.logging.utils.clear_existing_handlers(logger: logging.Logger) None

Removes all existing handlers from the logger.

Args: logger (logging.Logger): The logger from which to remove handlers.

extended_data.logging.utils.sanitize_json_data(data: Any) Any

Sanitize data for JSON serialization using Extended Data core utilities.

This function leverages make_raw_data_export_safe from Extended Data core to recursively convert complex types to export-safe primitives, including datetime objects, Path objects, and handling of large numbers.

Args: data: The data to sanitize.

Returns: Any: The sanitized data suitable for JSON serialization.

extended_data.logging.utils.add_labeled_json(msg: str, labeled_data: collections.abc.Mapping[str, collections.abc.Mapping[str, Any]]) str

Add labeled JSON data to the message.

Args: msg: The base message to append data to. labeled_data: The labeled JSON data to append.

Returns: str: The message with appended labeled JSON data.

extended_data.logging.utils.add_unlabeled_json(msg: str, json_data: collections.abc.Mapping[str, Any] | collections.abc.Sequence[collections.abc.Mapping[str, Any]]) str

Add unlabeled JSON data to the message.

Args: msg (str): The base message to append data to. json_data (Mapping[str, Any] | Sequence[Mapping[str, Any]]): The JSON data to append.

Returns: str: The message with appended unlabeled JSON data.

extended_data.logging.utils.add_json_data(msg: str, json_data: collections.abc.Mapping[str, Any] | collections.abc.Sequence[collections.abc.Mapping[str, Any]] | None, labeled_json_data: collections.abc.Mapping[str, collections.abc.Mapping[str, Any]] | None) str

Add JSON data to the log message.

Args: msg (str): The base message to append data to. json_data (Mapping[str, Any] | Sequence[Mapping[str, Any]] | None): The JSON data to append. labeled_json_data (Mapping[str, Mapping[str, Any]] | None): The labeled JSON data to append.

Returns: str: The message with appended JSON data.