hexastack-logging
Structured logging, security sanitization, and adapter integrations (Loguru, Rich, Structlog) for Hexastack.
1. Overview & Capabilities
hexastack-logging provides high-performance, structured telemetry across the entire Hexastack lifecycle:
- Multiple Backend Adapters: Native implementations for
Loguru,Rich,Structlog,SentryErrorAdapter(Sentry SDK integration), and standard library structured logging. - Security & PII Sanitization: Automatic masking of sensitive fields (passwords, tokens, authorization headers, credit cards).
- Formatters: JSON formatting for cloud aggregators (Datadog, CloudWatch) and colored console formatting for local development.
- Context & Correlation Integration: Injects active
correlation_idfrom async context into all log outputs. - Log Filtering & Levels: Fine-grained level filtering and module-based log routing.
2. Package Anatomy & Key Components
hexastack_logging/
├── domain/ # LogRecord, LogLevel, Logging exceptions
├── ports/ # LoggerPort, FormatterPort, FilterPort, SanitizerPort
├── adapters/ # LoguruAdapter, RichAdapter, StructlogAdapter, StructuredLogger, SentryErrorAdapter
└── infra/ # LoggingBootstrapper (order=10), Formatters, Sanitizers, Config
Key Exports
| Category | Exports |
|---|---|
| Adapters | StructuredLogger, LoguruAdapter, RichAdapter, StructlogAdapter, SentryErrorAdapter |
| Bootstrap | LoggingBootstrapper (order=10), HexastackLoggingConfig |
| Formatters | JsonFormatter, ConsoleFormatter |
| Sanitization | SanitizerFilter, mask_sensitive_data |
3. Monorepo & Sibling Relationships
graph TD
subgraph SiblingConsumers ["Consumers of LoggerPort"]
CQRS["hexastack-cqrs (LoggingMiddleware)"]
FASTAPI["hexastack-fastapi (HttpLoggingMiddleware)"]
GRPC["hexastack-grpc (LoggingServerInterceptor)"]
GRAPHQL["hexastack-graphql (CorrelationExtension)"]
CORE_CTX["hexastack-core (get_correlation_id)"]
end
subgraph LoggingSubsystem ["hexastack-logging"]
BOOT["LoggingBootstrapper (order=10)"]
ADAPTERS["Adapters (Loguru / Rich / Structlog / StdLib)"]
SAN["PII Sanitizer & JSON Formatter"]
end
BOOT --> ADAPTERS
ADAPTERS --> SAN
ADAPTERS -. reads context .-> CORE_CTX
CQRS -. resolves from DI .-> ADAPTERS
FASTAPI -. resolves from DI .-> ADAPTERS
GRPC -. resolves from DI .-> ADAPTERS
GRAPHQL -. resolves from DI .-> ADAPTERS
Explicit Dependencies (Direct)
hexastack-core: AbstractLoggerPort, DI container, and async context tracking.
Implied / Behavioral Relationships (DI-Mediated)
- Dependency Provider: Binds
LoggerPortinto the DI container atorder=10(before CQRSorder=20), ensuring telemetry is available to all subsequent bootstrappers and middlewares. - Correlation ID Synchronization: Automatically reads and outputs
get_correlation_id()stored inhexastack_core.utils.context.
Optional Integrations (Extras)
[loguru]: Enablesloguru>=0.7.0.[rich]: Enablesrich>=13.0.0console formatting.[structlog]: Enablesstructlog>=24.0.0.[all]: Installs all optional logging backends.
4. Installation
# Standalone standard library logging
pip install hexastack-logging
# With Loguru and Rich support
pip install "hexastack-logging[loguru,rich]"
# All logging backends
pip install "hexastack-logging[all]"
# Via umbrella package
pip install hexastack
5. Configuration Reference
[hexastack.logging]
level = "INFO" # "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
format = "json" # "json", "console"
backend = "structlog" # "standard", "loguru", "rich", "structlog"
sanitize_keys = ["password", "token", "secret", "authorization", "api_key"]
6. Quickstart Example
from hexastack_core.infra.bootstrap import bootstrap
from hexastack_core.ports.logging import LoggerPort
runtime = bootstrap(
config_overrides={
"logging": {
"level": "DEBUG",
"format": "console",
}
}
)
logger = runtime.container.get(LoggerPort)
logger.info("Application initialized successfully", extra={"user_count": 42})
Metadata
Release files for hexastack-logging 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hexastack_logging-0.6.0.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hexastack_logging-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.0 kB
Release files / hexastack_logging-0.6.0.tar.gz
| Download URL | hexastack_logging-0.6.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d254d3ebe37f4d6fba14acd78ea87fc6a0f9bf19aef16b29fdee0dc69805750b
|
|
BLAKE2b-256 checksum How to use checksums |
bb3c392a8f4918005043ff20d026b81d247c7252048c7c16270d7732daaa92b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / hexastack_logging-0.6.0-py3-none-any.whl
| Download URL | hexastack_logging-0.6.0-py3-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ab37df76b2dcb1997375430dc3d1cc4b6c07ff84305de880aadab1d5df12bca
|
|
BLAKE2b-256 checksum How to use checksums |
962a3f8372bb41c6c42afcb08a4971e6977679aad575fd18d331f0328ab1aa75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|