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 code
- path- Request path
- params- Query parameters
- version- HTTP protocol version
- host- Request host
- remote_addr- Client IP address
- real_ip- Client real IP (when behind proxy)
- request_id- Auto-generated or extracted request ID
- size- Response size in bytes
- duration- Request duration in seconds
- duration_millis- Request duration in milliseconds
- datetime- Timestamp in RFC3339 format
- user_agent- Client user agent
- referer- Request referrer
You can also log custom request headers, response headers, and environment variables.
Feature Flags
- log(default) - Enable integration with the standard- logcrate
- tracing-request-id- Enable integration with- tracing-actix-web's request ID
- uuid_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.