logging option in sonamu.config.ts.
What is LogTape?
LogTape is a structured logging library for TypeScript. Instead of simple string logs, it records logs as structured data.Regular Logging vs Structured Logging
Regular logging (string):Benefits of Structured Logging
- Easy search/filtering - Easily find logs matching specific conditions
- Analyzable - Aggregate log data and generate statistics
- Type safe - TypeScript validates log data structure
- Flexible output - Output same log in multiple formats (console, file, external services)
Core Concepts
1. Sink (Output Destination)
Where logs are ultimately recorded.- Console: Real-time monitoring
- File: Permanent storage
- Sentry: Error notifications
2. Filter (Filtering Conditions)
Determines which logs to record.3. Logger (Logger Configuration)
Connects categories, Sinks, and Filters.Sink-Filter-Logger Relationship
Example:Log Level Selection Guide
Log levels indicate the importance of logs.Meaning and Usage of Each Level
1. debug- Meaning: Detailed debugging information
- When to use: Problem tracking during development
- Examples: Function call order, variable values
- Meaning: General operational information
- When to use: Confirming normal operation
- Examples: HTTP requests/responses, task completion
- Meaning: Potential problem warning
- When to use: Not an error but needs attention
- Examples: Slow responses, retries occurring
- Meaning: Recoverable error
- When to use: Exception handling, recoverable failures
- Examples: Validation failure, API call failure
- Meaning: Critical failure (server shutdown level)
- When to use: Unrecoverable serious problems
- Examples: DB connection failure, out of memory
Recommended Levels by Environment
Level Hierarchy:
Setting a lower level outputs all higher levels. Example: Setting
lowestLevel: "warning" outputs
warning, error, and fatal.Why is it Designed This Way?
1. Default Values are Safe
Sonamu’s default configuration:- ✅ Only
/apipaths logged → Excludes unnecessary static file requests - ✅
infolevel → Not too much, not too little - ✅ Excludes healthcheck → Excludes repetitive requests from monitoring systems
2. Extensible
You can add custom settings on top of default settings:3. Minimal Performance Impact
Block unnecessary logs early through Filters:Default Configuration
If you omit thelogging option, default settings are automatically applied.
- Logs Fastify requests/responses to console
- Only logs
/api/*paths (excluding healthcheck) - Pretty format output (timestamp, category, level)
logging Options
Disable Logging
fastifyCategory
Specifies the category to use for Fastify HTTP logging. Type:readonly string[]
Default: ["fastify"]
["a", "b", "c"] array represents hierarchy
Log output example:
sinks
Add destinations (sinks) for log output. Type:Record<string, Sink>
filters
Add conditions for selective log filtering. Type:Record<string, FilterLike>
loggers
Configure which sinks and filters to use per category. Type:LoggerConfig[]
If there’s a logger configuration for the category set in
fastifyCategory, Sonamu won’t add the
default logger.Basic Examples
Minimal Configuration (Using Defaults)
Disable Logging
Custom Category
Default Behavior Details
Sonamu automatically configures logging as follows:1. Fastify Sink Auto-Generation
- Shows HTTP method and response code:
[GET:200] - Shows request URL:
/api/user/list - Colors distinguish levels
2. Fastify Filter Auto-Generation
3. Logger Auto-Generation
4. Meta Logger Disabled
Log Levels
LogTape log levels (in ascending order):- debug - Detailed debugging information
- info - General information (default)
- warning - Warning
- error - Error
- fatal - Fatal error
Practical Examples
- Development
- Staging
- Production
debuglevel to check all details- Console output for real-time viewing
- Fast feedback loop
Adding File Logging
Production Configuration
Fastify Logging Auto-Integration
Sonamu automatically integrates Fastify logging with the@logtape/fastify package.
- HTTP requests (method, URL)
- Response codes
- Response times
- Error stack traces
Important Notes
1. Overwriting Default sink/filter
2. logger Option When Logging is Disabled
3. Category Consistency
Next Steps
Sinks & Filters
Control log output precisely with custom Sinks and Filters
Category Logging
Manage logs systematically with the category system
Fastify Logging
Customize HTTP request/response logging
LogTape Documentation
Learn advanced features in the official LogTape documentation