syslog hook sends logs to syslog daemons (local or remote), enabling integration with traditional Unix logging infrastructure and centralized log management systems.
Features
- Local syslog daemon integration
- Remote syslog via TCP/UDP
- RFC5424 formatter support
- Priority mapping to syslog severity levels
- Custom formatting for log entries
- Thread-safe operation
Installation
github.com/drossan/go_logs/hooks.
Basic Usage
Local Syslog
Remote Syslog
Configuration
SyslogConfig
Custom Configuration
Syslog Priorities
Combine facility and severity:Level Mapping
go_logs levels are automatically mapped to syslog severities:| go_logs Level | Syslog Severity |
|---|---|
| TraceLevel | LOG_DEBUG |
| DebugLevel | LOG_DEBUG |
| InfoLevel | LOG_INFO |
| WarnLevel | LOG_WARNING |
| ErrorLevel | LOG_ERR |
| FatalLevel | LOG_CRIT |
Filtering by Level
Custom Formatters
Default Format
By default, logs are formatted as:RFC5424 Format
Custom Formatter
Complete Examples
Application with Local Syslog
Centralized Logging
Multiple Syslog Destinations
rsyslog Configuration
Receive Logs from Application
Edit/etc/rsyslog.conf:
Forward to Remote Server
systemd Journal Integration
Logs sent to syslog are automatically captured by systemd:Docker Integration
Syslog Logging Driver
Application with Syslog Hook
Kubernetes
Troubleshooting
Connection Refused
Permission Denied
Remote Connection Issues
Logs Not Appearing
Best Practices
-
Use appropriate facilities
-
Filter by level to reduce syslog volume
-
Use TCP for remote syslog (reliable delivery)
-
Tag with application name for filtering
-
Close hooks on shutdown
See Also
- Hooks - Hook system overview
- Formatters - Log formatting
- Production Setup - Deployment guide