Features
A comprehensive overview of what fapilog offers.
Core Logging
Feature |
Why It Matters |
|---|---|
Sync and async loggers |
Use |
Context managers |
|
Custom log levels |
Register domain-specific levels like |
Logger caching |
Loggers are cached by name by default, so repeated |
Configuration
Feature |
Why It Matters |
|---|---|
Presets |
Start with |
Environment detection |
Automatically detects Lambda, Kubernetes, Docker, and CI environments to apply appropriate settings |
Builder API |
Fluent |
Pydantic settings |
Configure via environment variables with type validation |
Performance
Feature |
Why It Matters |
|---|---|
Non-blocking writes |
Log calls enqueue and return immediately—I/O happens in background workers |
Lock-free queue |
|
Backpressure handling |
Choose between dropping logs (protect latency) or blocking (protect durability) when the queue fills |
Batching |
Logs are batched before writing to reduce I/O overhead |
Zero-copy processing |
|
Adaptive pipeline |
Automatic worker scaling, batch sizing, and filter tightening based on real-time pressure monitoring |
Structured Output
Feature |
Why It Matters |
|---|---|
JSON Lines format |
Machine-parseable output for log aggregators and analysis tools |
Pretty-print mode |
Human-readable output for local development (auto-detected when running in a terminal) |
Structured envelope |
Every log includes |
Origin tracking |
Logs are tagged as |
Context and Correlation
Feature |
Why It Matters |
|---|---|
Context binding |
Attach fields to a logger with |
Context variables |
|
Request ID tracking |
Built-in |
Async context preservation |
|
Redaction and Compliance
Feature |
Why It Matters |
|---|---|
Field masking |
Redact specific fields like |
Regex patterns |
Match and redact patterns like SSNs, credit card numbers, or API keys |
URL credential scrubbing |
Automatically redact credentials embedded in database URLs or API endpoints |
Compliance presets |
Built-in presets for |
Fail modes |
Choose |
Sinks
Feature |
Why It Matters |
|---|---|
Multiple destinations |
Write to stdout, files, HTTP endpoints, or cloud services simultaneously |
Rotating files |
|
Cloud-native sinks |
Direct integration with CloudWatch, Loki, and PostgreSQL |
Sink routing |
Route logs by level—send errors to a database while info goes to stdout |
Circuit breakers |
Failing sinks are temporarily disabled to prevent cascade failures |
Fallback sinks |
Specify a fallback destination when the primary sink trips its circuit breaker |
Filtering
Feature |
Why It Matters |
|---|---|
Level filtering |
Drop logs below a threshold |
Sampling |
Randomly sample a percentage of logs to reduce volume |
Rate limiting |
Limit logs per key (e.g., per endpoint or per user) to prevent floods |
Adaptive sampling |
Automatically increase sampling during error spikes to capture more context |
Trace sampling |
Sample entire request traces together so you don’t get incomplete pictures |
Enrichment
Feature |
Why It Matters |
|---|---|
Runtime info |
Automatically add PID, hostname, and Python version to every log |
Kubernetes metadata |
Add pod name, namespace, and labels when running in K8s |
Custom enrichers |
Implement the enricher protocol to add your own fields |
Exception Handling
Feature |
Why It Matters |
|---|---|
Full traceback capture |
Exceptions include complete stack traces with configurable depth |
Exception chaining |
Chained exceptions ( |
Unhandled exception capture |
Optionally log uncaught exceptions before they crash the process |
Stack truncation |
Limit stack trace size to prevent log bloat |
FastAPI Integration
Feature |
Why It Matters |
|---|---|
Builder pattern |
|
Request/response logging |
Automatic logging of incoming requests and outgoing responses |
Timing |
Request duration is captured and logged |
Context injection |
Use FastAPI dependencies to inject loggers with request context |
Resilience
Feature |
Why It Matters |
|---|---|
Plugin isolation |
A failing enricher or processor doesn’t crash your logging—errors are captured in diagnostics |
Graceful shutdown |
|
Drain operations |
Explicitly drain pending logs before shutdown |
Health checks |
Per-plugin health checks for monitoring |
Observability
Feature |
Why It Matters |
|---|---|
Prometheus metrics |
Export logging metrics (queue depth, batch sizes, errors) for monitoring |
Per-plugin timing |
Track how long each enricher, processor, and sink takes |
Diagnostics system |
Internal issues are logged with rate limiting to avoid log storms |
Extensibility
Feature |
Why It Matters |
|---|---|
Plugin architecture |
Add custom enrichers, redactors, filters, processors, and sinks |
Entry point discovery |
Plugins can be installed as packages and auto-discovered |
Allowlist/denylist |
Control which plugins are loaded in production |
Stdlib bridge |
Route Python’s standard |
Learn More
Why Fapilog? - When to choose fapilog over alternatives
Getting Started - Install and start logging
Core Concepts - Understand the architecture
Cookbook - Recipes for common problems