logging option of sonamu.config.ts.
What is a Sink?
A Sink is where logs are ultimately output. Examples:- Console (terminal)
- Files
- External logging services (Sentry, Datadog, etc.)
- Database
Why Sinks are Needed
Logs should be recorded in different places depending on their purpose: 1. Real-time Monitoring (Console)Using Multiple Sinks Simultaneously
You can send a single log to multiple Sinks at once:- Real-time viewing (console)
- Permanent storage (file)
- Immediate alerts (sentry)
What is a Filter?
A Filter is a condition for selectively outputting logs. Examples:- Only specific categories
- Only above a certain level
- Only specific URL patterns
- By time period
Why Filters are Needed
Recording all logs causes problems: 1. Performance DegradationFilter Usage Example
Sink vs Filter Differences
The two concepts have different purposes:Using Them Together
When to Use?
When to Add a Sink
1. When you need a new output destinationWhen to Add a Filter
1. When you only need logs matching specific conditionsSinks Configuration Details
sinks Option
Add custom Sinks tologging.sinks.
Type: Record<string, Sink>
Console Sink
Outputs logs to the terminal.File Sink
Saves logs to a file.Stream Sink
Outputs logs to a Node.js stream.Custom Sink
You can implement your own Sink.Filters Configuration
filters Option
Selectively filter logs. Type:Record<string, FilterLike>
URL-Based Filter
Level-Based Filter
Time-Based Filter
Property-Based Filter
Practical Examples
Development vs Production
Multiple Sinks & Filters
External Service Integration
Logging by URL Pattern
LogRecord Structure
TheLogRecord type used in Filters and custom Sinks:
category: Log category (e.g.,["fastify"])level: Log level ("debug"|"info"|"warning"|"error"|"fatal")message: Log message arraytimestamp: Time the log occurredproperties: Additional information (for Fastify:req,res, etc.)
Important Notes
1. Sink Name Conflicts
2. Filter Performance
3. Async Sinks
4. Filters are Sync Only
Next Steps
Category Logging
Manage logs systematically with the category system
Fastify Logging
Customize HTTP request/response logging
LogTape Setup
Learn basic logging configuration and concepts
LogTape Official Documentation
Check LogTapeβs advanced features and APIs