lifecyclelogging.utils
Utility helpers for LifecycleLogging internals.
Module Contents
Section titled “Module Contents”Functions
Section titled “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-types 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. |
lifecyclelogging.utils.get_log_level(level: int | str) → int
Section titled “lifecyclelogging.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.
lifecyclelogging.utils.get_loggers() → list[logging.Logger]
Section titled “lifecyclelogging.utils.get_loggers() → list[logging.Logger]”Retrieves all active loggers.
Returns: list[logging.Logger]: A list of all active logger instances.
lifecyclelogging.utils.find_logger(name: str) → logging.Logger | None
Section titled “lifecyclelogging.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.
lifecyclelogging.utils.clear_existing_handlers(logger: logging.Logger) → None
Section titled “lifecyclelogging.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.
lifecyclelogging.utils.sanitize_json_data(data: Any) → Any
Section titled “lifecyclelogging.utils.sanitize_json_data(data: Any) → Any”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.
lifecyclelogging.utils.add_labeled_json(msg: str, labeled_data: collections.abc.Mapping[str, collections.abc.Mapping[str, Any]]) → str
Section titled “lifecyclelogging.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.
lifecyclelogging.utils.add_unlabeled_json(msg: str, json_data: collections.abc.Mapping[str, Any] | collections.abc.Sequence[collections.abc.Mapping[str, Any]]) → str
Section titled “lifecyclelogging.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.
lifecyclelogging.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
Section titled “lifecyclelogging.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.