Skip to main content
Sonamu automatically logs Fastify HTTP requests and responses. It’s integrated with LogTape through the @logtape/fastify package.

Why HTTP Logging is Important

HTTP logs are essential for web service operations.

1. Troubleshooting

Error tracking:
Bug reproduction:

2. Performance Monitoring

Discovering slow requests:
Detecting bottlenecks:

3. Security Monitoring

Detecting abnormal access:
Discovering attack patterns:

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
2. Response Information
  • Status code (200, 404, 500)
  • Response time
3. Error Information
  • Error message
  • Stack trace

Things NOT to Log

Security information:
Personal information:

Log Level Selection

info - Normal requests
  • 2xx, 3xx status codes
  • Normal business flow
warning - Needs attention
  • Slow responses (>1 second)
  • 4xx status codes (client errors)
  • Rate limiting
error - Server errors
  • 5xx status codes
  • Exceptions occurred
  • DB connection failures

Using responseTime

responseTime is the time taken for API response (in milliseconds).

Performance Criteria

Performance Monitoring Configuration

Performance Analysis

Automatic Logging

HTTP logging is automatically enabled without additional configuration.
Automatically logged information:
  • 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

Format structure:

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.
Log output:

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

Output:

Detailed Format

Output:

JSON Format

Output:

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