@logtape/fastify package.
Why HTTP Logging is Important
HTTP logs are essential for web service operations.1. Troubleshooting
Error tracking:2. Performance Monitoring
Discovering slow requests:3. Security Monitoring
Detecting abnormal access:4. Business Analysis
Usage pattern analysis:What Should Be Logged?
Essential Logging Items
1. Request Information- HTTP method (GET, POST, PUT, DELETE)
- URL path
- Timestamp
- Status code (200, 404, 500)
- Response time
- Error message
- Stack trace
Things NOT to Log
Security information:Log Level Selection
info - Normal requests- 2xx, 3xx status codes
- Normal business flow
- Slow responses (>1 second)
- 4xx status codes (client errors)
- Rate limiting
- 5xx status codes
- Exceptions occurred
- DB connection failures
Using responseTime
responseTime is the time taken for API response (in milliseconds).
Performance Criteria
| Time | Rating | Action |
|---|---|---|
| < 100ms | Very fast | Maintain |
| 100-500ms | Acceptable | Monitor |
| 500ms-1s | Slow | Review optimization |
| > 1s | Very slow | Optimize immediately |
Performance Monitoring Configuration
Performance Analysis
Automatic Logging
HTTP logging is automatically enabled without additional configuration.- HTTP method (GET, POST, PUT, DELETE, etc.)
- Request URL
- Response code (200, 404, 500, etc.)
- Response time
- Error stack trace (when errors occur)
Default Log Format
Default Behavior
1. Logging Target
By default, only paths starting with/api are logged.
2. Default sink
Sonamu automatically creates a"fastify-console" sink.
Features:
- Console output
- Pretty format (pretty formatter)
- HTTP method and response code display
- Timestamp, category display
3. Default filter
A"fastify-console" filter is automatically created.
Conditions:
- URL starts with
/api - Excludes
/api/healthcheck
4. Default logger
Customizing fastifyCategory
You can change the category used for Fastify logging.LogRecord Properties
Fastify logs include special properties.req Property
res Property
responseTime Property
Custom Filters
URL Pattern Filtering
Status Code Filtering
Slow Request Filtering
Custom Formatters
Simple Format
Detailed Format
JSON Format
Practical Examples
Development Environment Configuration
Production Configuration
Log Separation by Path
Slow Request Monitoring
Disabling Logging
Complete Disable
Disable Only Fastify Logging
Exclude Specific Paths
Important Notes
1. req vs res Properties
2. responseTime Only Exists in res
3. Caution When Overwriting fastify-console
4. Fastify logger Option Conflict
Next Steps
Category Logging
Manage logs systematically with the category system
Sinks & Filters
Control log output with custom Sinks and Filters
LogTape Setup
Learn basic logging configuration and concepts
LogTape Official Documentation
Check advanced features including Fastify integration