Skip to content

lifecyclelogging.utils

Utility helpers for LifecycleLogging internals.

get_log_levelConverts a log level from string or integer to a logging level integer.
get_loggersRetrieves all active loggers.
find_loggerFinds a logger by its name.
clear_existing_handlersRemoves all existing handlers from the logger.
sanitize_json_dataSanitize data for JSON serialization using extended-data-types utilities.
add_labeled_jsonAdd labeled JSON data to the message.
add_unlabeled_jsonAdd unlabeled JSON data to the message.
add_json_dataAdd JSON data to the log message.

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.

Retrieves all active loggers.

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

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.

Removes all existing handlers from the logger.

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

Sanitize data for JSON serialization using extended-data-types utilities.

This function leverages make_raw_data_export_safe from extended-data-types 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.

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.

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.

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.