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, 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
└── infra/ # LoggingBootstrapper (order=10), Formatters, Sanitizers, Config
Key Exports
| Category | Exports |
|---|---|
| Adapters | StructuredLogger, LoguruAdapter, RichAdapter, StructlogAdapter |
| 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})
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hexastack_logging-0.0.0.tar.gz
(10.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hexastack_logging-0.0.0.tar.gz.
File metadata
- Download URL: hexastack_logging-0.0.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b939343321bcb2b3bc1efd4a7edf81cf9ce0506e22ecb999f98e52db8f42b19c
|
|
| MD5 |
c2d5ffbe6b7af89e9ed8e659a1853014
|
|
| BLAKE2b-256 |
d30abb5c7906e72fcd32a34bc1fef3e2619f294dcb867958068928dbde1526de
|
File details
Details for the file hexastack_logging-0.0.0-py3-none-any.whl.
File metadata
- Download URL: hexastack_logging-0.0.0-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
402e564643b0b4615f9c239ef5412a412b7d6986bb81b751897d59d2c7bad76d
|
|
| MD5 |
e85718dea466578e50c9c61c6d0f84e2
|
|
| BLAKE2b-256 |
7998e14a88558b34a2a77f236e632bf13c416a0645e04ab4379ee0a29e421b2e
|