Exception Hierarchy
This module defines the logging package exception hierarchy. It provides semantic error classes that make failure handling cleaner and easier to route in application code.
Behavior and Context
All custom exceptions derive from LoggerError:
- LoggerConfigError
- LoggerFileError
- LoggerDependencyError
This allows both broad and narrow exception handling strategies.
Purpose
- Typed Failure Signals: Differentiate config, file, and dependency failures.
- Cleaner Call Sites: Catch package-specific errors with a single base type.
- Consistent API Contract: Shared error vocabulary across modules.
High-Level API & Examples
Example 1: Catch Any Logging Error
from jazzmine.logging import BaseLogger, LoggerError
try:
logger = BaseLogger("missing-config.yml")
logger.resolve_config()
except LoggerError as exc:
print("logging setup failed:", exc)Example 2: Handle Dependency Failure Separately
from jazzmine.logging import BaseLogger, LoggerDependencyError
try:
logger = BaseLogger({
"name": "service",
"level": "INFO",
"json": True,
"sinks": [{"type": "sentry", "dsn": "..."}],
})
logger.resolve_config()
# sink.initialize() occurs during start_async_workers
except LoggerDependencyError as exc:
print("optional package missing:", exc)Detailed Class Functionality
class LoggerError(Exception)
Base class for all logging subsystem errors.
class LoggerConfigError(LoggerError)
Raised for invalid configuration shape, unsupported sink types, or parsing issues.
class LoggerFileError(LoggerError)
Raised for file-related failures, such as missing config files or invalid log file targets.
class LoggerDependencyError(LoggerError)
Raised when optional runtime dependencies (for example requests, aiohttp, boto3) are required but unavailable.
Error Handling
This module only defines exception classes; raising behavior is implemented in other modules.
Remarks
- Prefer catching LoggerError at service boundaries and more specific subclasses in setup internals.
- Keep new exception types in this module to preserve a centralized error taxonomy.
Request Context Model
RequestContext is a lightweight dataclass used to attach request-scoped metadata to structured logs. It is designed to improve traceability across distributed and conversational systems.
Synchronous HTTP Handler
SyncHTTPHandler is a stdlib logging.Handler implementation that forwards log records to an HTTP endpoint using the requests library.