apifrom.logging_utils ===================== Logging utilities module for APIFromAnything. This module provides enhanced logging functionality for the application. It includes structured logging, log rotation, and integration with external logging services. .. py:currentmodule:: apifrom.logging_utils Overview -------- **Classes** * :py:class:`StructuredLogFormatter` **Functions** * :py:func:`configure_logging_dict` * :py:func:`get_logger` * :py:func:`log_execution_time` * :py:func:`setup_sentry` Classes ------- .. py:class:: StructuredLogFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None):bases: logging.Formatter Formatter for structured JSON logs. This formatter outputs logs in JSON format with additional context information such as timestamp, level, module, and process ID. Initialize the formatter with specified format strings. Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format. Use a style parameter of '%', '{' or '$' to specify that you want to use one of %-formatting, :meth:`str.format` (``{}``) formatting or :class:`string.Template` formatting in your format string. .. versionchanged:: 3.2 Added the ``style`` parameter. .. method:: format(record) Format the log record as a JSON string. :param record: The log record to format. :returns: A JSON string representation of the log record. Functions --------- .. py:function:: configure_logging_dict(log_level = 'INFO', log_format = 'structured', log_file = None, max_bytes = 10485760, backup_count = 5) Create a logging configuration dictionary. :param log_level: The logging level. :param log_format: The log format ('structured' for JSON, 'simple' for text). :param log_file: The path to the log file. If None, logs will be sent to stdout. :param max_bytes: The maximum size of the log file before rotation. :param backup_count: The number of backup log files to keep. :returns: A logging configuration dictionary. .. py:function:: get_logger(name, extra = None) Get a logger with the specified name and extra context. :param name: The name of the logger. :param extra: Extra context to include in all log messages. :returns: A configured logger instance. .. py:function:: log_execution_time(logger = None, level = logging.DEBUG) Decorator to log the execution time of a function. :param logger: The logger to use. If None, a logger will be created. :param level: The logging level to use. :returns: A decorator function. .. py:function:: setup_sentry(dsn, environment, release) Set up Sentry for error tracking. :param dsn: The Sentry DSN. :param environment: The environment name. :param release: The release version.