Skip to main content
Sinks determine where logs are output, and Filters determine which logs to output. You can add custom sinks and filters in the 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)
2. Permanent Storage (File)
3. Error Notifications (External Service)
4. Statistical Analysis (Database)

Using Multiple Sinks Simultaneously

You can send a single log to multiple Sinks at once:
Benefits:
  • 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 Degradation
2. Disk Space Waste
3. Readability Degradation

Filter 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 destination
2. When recording in a different format
3. When recording to multiple places simultaneously

When to Add a Filter

1. When you only need logs matching specific conditions
2. When you want to improve performance
3. When you want to send different logs to different Sinks

Sinks Configuration Details

sinks Option

Add custom Sinks to logging.sinks. Type: Record<string, Sink>
The name "fastify-console" is the default Sink automatically generated by Sonamu. Adding with this name will overwrite the default 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>
The name "fastify-console" is the default Filter automatically generated by Sonamu. Adding with this name will overwrite the default Filter.

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

The LogRecord type used in Filters and custom Sinks:
Key properties:
  • category: Log category (e.g., ["fastify"])
  • level: Log level ("debug" | "info" | "warning" | "error" | "fatal")
  • message: Log message array
  • timestamp: Time the log occurred
  • properties: Additional information (for Fastify: req, res, etc.)
Fastify’s properties:

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