HTTP Ledger
HTTP Ledger is a comprehensive Express.js middleware for detailed API request and response logging. It provides beautiful console output, advanced security features, performance metrics, and highly customizable logging options.Overview
HTTP Ledger captures complete information about every HTTP request and response in your Express application, making it easy to monitor, debug, and analyze your API traffic. The middleware is designed to be production-ready with minimal overhead and extensive configuration options.Key Features
Comprehensive Logging
Captures method, URL, status code, timing, request/response sizes, headers, query parameters, and bodies
Advanced Security
Field masking for sensitive data like passwords, tokens, and API keys with support for nested fields
Custom Logging
Custom formatters, log levels, and selective logging to match your application’s needs
Performance Optimized
Log sampling, conditional logging, and async operations for minimal performance impact
Request Tracking
Auto-generated request IDs for distributed tracing and request correlation
Error Handling
Robust error handling with graceful fallbacks and comprehensive error capture
IP Information
Optional IP geolocation support for geographic analysis of API traffic
TypeScript Support
Full TypeScript support with comprehensive type definitions included
What Gets Logged?
HTTP Ledger captures detailed information about each request:- Request Details: HTTP method, URL, headers, query parameters, body
- Response Details: Status code, headers, body, content type
- Performance Metrics: Time taken, request size, response size
- Client Information: User agent, referer, IP address, geolocation
- Request Tracking: Request IDs, timestamps, HTTP version
- Error Information: Error messages, stack traces, error codes
Use Cases
- Development: Debug API issues with detailed request/response logs
- Production Monitoring: Track API performance and identify bottlenecks
- Security Auditing: Monitor API access patterns and detect anomalies
- Analytics: Send log data to external services for analysis
- Compliance: Maintain audit trails of API access
- Performance Optimization: Identify slow endpoints and optimize them
Example Output
Here’s an example of the JSON output produced by HTTP Ledger:Performance Considerations
HTTP Ledger is optimized for production use:- Minimal Overhead: Efficient implementation with minimal performance impact
- Async Operations: IP lookups and callbacks run asynchronously without blocking
- Memory Efficient: Streams large responses without buffering
- Configurable: Disable expensive operations when not needed
- Log Sampling: Reduce logging overhead in high-traffic environments
- Selective Logging: Skip logging for health checks and static assets
HTTP Ledger requires Node.js 18.0.0 or higher and Express 4.x or higher.
Next Steps
Installation
Install HTTP Ledger in your project
Quick Start
Get started with a working example