actix-web-middleware-slogger
A structured logging middleware for Actix Web, inspired by the Logger middleware from actix-web.
Terms of use
By using this project or its source code, for any purpose and in any shape or form, you grant your implicit agreement to all the following statements:
- You condemn Russia and its military aggression against Ukraine
- You recognize that Russia is an occupant that unlawfully invaded a sovereign state
- You support Ukraine's territorial integrity, including its claims over temporarily occupied territories of Crimea and Donbas
- You reject false narratives perpetuated by Russian state propaganda
Features
- 🔄 Structured logging of HTTP requests and responses
- ⚙️ Fields selection (method, path, duration, headers, etc.)
- 📋 Support for standard
logcrate integration - 🔍 Request ID tracking (with UUID v4 or v7 support)
- 🔗 Integration with tracing ecosystem via
tracing-request-idfeature - 🧩 Pattern-based path exclusion
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Usage
use tokio;
use actix_web;
use ;
use SLogger;
use ;
async
With Tracing Integration
Use the tracing-request-id feature to integrate with the tracing ecosystem:
[]
= { = "0.1.0", = ["tracing-request-id"] }
use tokio;
use actix_web;
use ;
use SLogger;
use ;
use TracingLogger;
async
Configuration
Custom Fields
You can customize which fields are included in your logs:
use ;
let logger = new;
Path Exclusions
Exclude specific paths from logging:
let logger = default
.exclude
.exclude;
Or use regex patterns:
let logger = default
.exclude_regex;
Custom Log Target
Change the logger target name:
let logger = default.log_target;
Available Fields
The following fields can be added to your log output:
method- HTTP method (GET, POST, etc.)status- Response status codepath- Request pathparams- Query parametersversion- HTTP protocol versionhost- Request hostremote_addr- Client IP addressreal_ip- Client real IP (when behind proxy)request_id- Auto-generated or extracted request IDsize- Response size in bytesduration- Request duration in secondsduration_millis- Request duration in millisecondsdatetime- Timestamp in RFC3339 formatuser_agent- Client user agentreferer- Request referrer
You can also log custom request headers, response headers, and environment variables.
Feature Flags
log(default) - Enable integration with the standardlogcratetracing-request-id- Enable integration withtracing-actix-web's request IDuuid_v7- Use UUIDv7 instead of UUIDv4 for request IDs
License
This project is licensed under the MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.