Logging Overview
NATS Server provides flexible logging capabilities to monitor server operations, debug issues, and audit activity.Log Levels
NATS supports multiple log levels:- Info - Normal operational messages (default)
- Warning - Warning messages for potential issues
- Error - Error messages for failures
- Fatal - Fatal errors that cause server shutdown
- Debug - Detailed debugging information
- Trace - Protocol-level tracing
Log Output Configuration
Standard Error (Default)
By default, logs go to stderr:File Output
Redirect logs to a file:Log File Rotation
Automatic log rotation based on size:- Current log renamed to
nats-server.log.2026.03.04.10.15.30 - New log file created
- Configurable maximum number of archived log files
Disable Timestamps
Remove timestamps from logs:Debug Logging
Enable detailed debug output:- Client connections and disconnections
- Subscription operations
- Route establishment
- Account operations
- Authentication attempts
Trace Logging
Enable protocol-level tracing:Verbose Trace
Trace including system account (from main.go:51):Limit Traced Message Length
Limit message payload length in trace logs:Syslog Support
Send logs to syslog or Windows Event Log:Local Syslog
Remote Syslog
Send to remote syslog server:Syslog Configuration
From logger/syslog.go, NATS supports:- Unix socket:
/dev/log,/var/run/syslog - UDP:
udp://host:port - TCP:
tcp://host:port
Log Format
Standard Format
Default log format (from logger/log.go:74-95):Components
- [PID] - Process ID (optional, enabled with
pid: true) - YYYY/MM/DD HH:MM:SS.microseconds - Timestamp with microsecond precision
- [LEVEL] - Log level: INF, WRN, ERR, FTL, DBG, TRC
- message - Log message
Colored Output
When outputting to terminal, logs can be colored:Colors are disabled when logging to file or piping output.
Structured Logging
NATS logs include structured information:Client Connection Logs
- IP address and port
- Connection ID (cid)
- Event description
Account Logs
Authentication Logs
Error Logs
Log Configuration Examples
Production Configuration
Development Configuration
High-Volume Production
Debugging Issues
Log Rotation Strategy
Size-Based Rotation
From logger/log.go implementation:- When log reaches 100MB, rotate
- Old log renamed with timestamp
- New log file created
- Process continues without interruption
External Rotation (logrotate)
Use system log rotation: /etc/logrotate.d/nats-server:Runtime Log Control
Change log levels without restart:ldm- Toggle debug and trace loggingreopen- Reopen log filereload- Reload configuration
Performance Considerations
Log Level Impact
- Info/Warn/Error: Minimal performance impact
- Debug: Low to moderate impact (~5-10% overhead)
- Trace: Significant impact (~20-50% overhead)
Recommendations
- Production: Use info level only
- Staging: Enable debug for issues
- Development: Use debug or trace freely
- Performance testing: Disable debug and trace
Async Logging
From logger/log.go implementation, file logging is buffered:- Writes are buffered to reduce I/O
- Automatic flush on rotation
- Minimal blocking of main thread
Monitoring Logs
Log Aggregation
Forward logs to aggregation systems:Alerting
Monitor for critical patterns:[ERR]- Error conditions[FTL]- Fatal errorsAuthorization violation- Security issuesslow consumer- Performance issues