Log Service
Overview
The Log Service (gc_log_service) is a centralized logging service that collects, stores, and provides access to logs from various applications and services in the NextGen Gateway ecosystem. It receives log entries over TCP, stores them in CSV files, and allows clients to query logs based on different criteria.
Features
Core Functionality
- Centralized Logging: Aggregates logs from multiple services and runtimes
- Persistent Storage: Stores logs in configurable directory as CSV files
- Log Querying: Allows searching logs by service name, time range, severity, and more
- TCP Interface: Simple TCP-based protocol for receiving and querying logs
Syslog Forwarding (v0.7.0+)
Starting with version 0.7.0, the Log Service supports syslog forwarding to external syslog servers. This feature enables integration with existing enterprise syslog/SIEM solutions for centralized log management.
Syslog Forwarding
Overview
The syslog forwarding feature allows the Log Service to forward received log entries to external syslog servers using UDP, TCP, or TLS protocols. This is completely optional and disabled by default, ensuring backward compatibility with existing deployments.
Use Cases
| Use Case | Description |
|---|---|
| Centralized Logging Integration | Forward logs to enterprise syslog/SIEM solutions (Splunk, ELK, Graylog, etc.) |
| Compliance & Audit | Meet organizational logging requirements for retention and audit |
| Redundancy | Maintain local CSV files while also forwarding to remote syslog servers |
| Scalability | Offload log storage to dedicated logging infrastructure |
Protocols Supported
| Protocol | Description | Port |
|---|---|---|
| UDP | Fast, connectionless, unreliable | 514 (default) |
| TCP | Reliable, connection-oriented | 514 or 6514 |
| TLS | Encrypted, reliable (RFC 5425) | 6514 |
Message Formats
| Format | Description | Standard |
|---|---|---|
| RFC 3164 | BSD syslog format (traditional) | RFC 3164 |
| RFC 5424 | Structured syslog format | RFC 5424 |
Configuration
Storage Modes
The Log Service supports three storage modes:
| Mode | Local CSV | Syslog Forward | Use Case |
|---|---|---|---|
local |
✓ | ✗ | Default, standalone deployments |
syslog |
✗ | ✓ | Centralized logging only |
both |
✓ | ✓ | Redundancy and backup |
Note: When using
syslogmode, logs are NOT stored locally. Ensure your syslog server is reliable or consider usingbothmode for redundancy.
Quick Start
Enable Syslog Forwarding via Environment Variables
gc_log_service \
--storage-mode both \
--syslog-address logserver.company.com \
--syslog-port 514 \
--syslog-protocol udp \
--syslog-facility 1Enable via Configuration File
Add to your service configuration:
{
"storage_mode": "both",
"syslog_enabled": true,
"syslog_address": "logserver.company.com",
"syslog_port": 514,
"syslog_protocol": "udp",
"syslog_facility": 1,
"syslog_format": "rfc5424",
"syslog_app_name": "nextgen_gateway",
"syslog_hostname": "gc-gateway-01"
}Full Configuration Options
Core Settings
| Option | Type | Default | Description |
|---|---|---|---|
storage_mode |
enum | local |
Storage destination: local, syslog, or both |
syslog_enabled |
bool | false |
Enable syslog forwarding |
Syslog Destination
| Option | Type | Default | Description |
|---|---|---|---|
syslog_address |
string | - | Syslog server hostname or IP address |
syslog_port |
u16 | 514 | Syslog server port |
syslog_protocol |
enum | udp |
Protocol: udp, tcp, or tls |
Syslog Formatting
| Option | Type | Default | Description |
|---|---|---|---|
syslog_facility |
u8 | 1 | Syslog facility (0-23) |
syslog_app_name |
string | gc_gateway |
Application name in syslog messages |
syslog_hostname |
string | system hostname | Hostname in syslog messages |
syslog_format |
enum | rfc3164 |
Message format: rfc3164 or rfc5424 |
TLS Configuration (TLS protocol only)
| Option | Type | Default | Description |
|---|---|---|---|
syslog_tls_ca_cert |
string | - | Path to CA certificate for server verification |
syslog_tls_client_cert |
string | - | Path to client certificate for mutual TLS |
syslog_tls_client_key |
string | - | Path to client private key |
syslog_tls_verify_server |
bool | true |
Verify server certificate |
Buffer Configuration (TCP/TLS protocols only)
| Option | Type | Default | Description |
|---|---|---|---|
syslog_buffer_bytes |
usize | 8,000,000 | Maximum memory in bytes for the message buffer. Messages are dropped when buffer is full. |
syslog_reconnect_delay_ms |
u64 | 100 | Base reconnection delay in milliseconds for exponential backoff. |
syslog_max_reconnect_attempts |
u32 | 5 | Maximum consecutive reconnection attempts before logging error. |
Environment Variables
All configuration options can also be set via environment variables:
# Core
export GC_LOG_STORAGE_MODE=both
export GC_LOG_SYSLOG_ENABLED=true
# Destination
export GC_LOG_SYSLOG_ADDRESS=logserver.company.com
export GC_LOG_SYSLOG_PORT=514
export GC_LOG_SYSLOG_PROTOCOL=udp
# Formatting
export GC_LOG_SYSLOG_FACILITY=1
export GC_LOG_SYSLOG_APP_NAME=nextgen_gateway
export GC_LOG_SYSLOG_HOSTNAME=gc-gateway-01
export GC_LOG_SYSLOG_FORMAT=rfc5424
# TLS
export GC_LOG_SYSLOG_TLS_CA_CERT=/etc/ssl/certs/syslog_ca.pem
export GC_LOG_SYSLOG_TLS_CLIENT_CERT=/etc/ssl/certs/client.pem
export GC_LOG_SYSLOG_TLS_CLIENT_KEY=/etc/ssl/private/client.key
export GC_LOG_SYSLOG_TLS_VERIFY_SERVER=true
# Buffer Configuration
export GC_LOG_SYSLOG_BUFFER_BYTES=8000000
export GC_LOG_SYSLOG_RECONNECT_DELAY_MS=100
export GC_LOG_SYSLOG_MAX_RECONNECT_ATTEMPTS=5Examples
Local Storage Only (Default)
# Store logs in CSV files only (backward compatible)
gc_log_service \
--writer-port 3003 \
--reader-port 3004 \
--log-dir /var/log/gc_gatewayForward to UDP Syslog Server
gc_log_service \
--storage-mode syslog \
--syslog-enabled true \
--syslog-address 192.168.1.100 \
--syslog-port 514 \
--syslog-protocol udp \
--syslog-facility 1 \
--log-dir /var/log/gc_gatewayLocal + UDP Syslog (Redundancy)
gc_log_service \
--storage-mode both \
--syslog-address logserver.local \
--syslog-port 514 \
--syslog-protocol udp \
--log-dir /var/log/gc_gatewayTCP Syslog with RFC 5424 Format
gc_log_service \
--storage-mode syslog \
--syslog-address logserver.company.com \
--syslog-port 6514 \
--syslog-protocol tcp \
--syslog-format rfc5424 \
--syslog-app-name nextgen_gateway \
--log-dir /var/log/gc_gatewayTLS with Server Certificate Verification
gc_log_service \
--storage-mode both \
--syslog-address logserver.company.com \
--syslog-port 6514 \
--syslog-protocol tls \
--syslog-format rfc5424 \
--syslog-tls-ca-cert /etc/ssl/certs/syslog_ca.pem \
--syslog-tls-verify-server true \
--log-dir /var/log/gc_gatewayMutual TLS (mTLS)
gc_log_service \
--storage-mode both \
--syslog-address logserver.company.com \
--syslog-port 6514 \
--syslog-protocol tls \
--syslog-tls-ca-cert /etc/ssl/certs/syslog_ca.pem \
--syslog-tls-client-cert /etc/ssl/certs/client.pem \
--syslog-tls-client-key /etc/ssl/private/client.key \
--syslog-tls-verify-server true \
--log-dir /var/log/gc_gatewayTCP with Custom Buffer and Reconnection Settings
gc_log_service \
--storage-mode both \
--syslog-address logserver.company.com \
--syslog-port 6514 \
--syslog-protocol tcp \
--syslog-format rfc5424 \
--syslog-buffer-bytes 16000000 \
--syslog-reconnect-delay-ms 200 \
--syslog-max-reconnect-attempts 10 \
--log-dir /var/log/gc_gatewayThis configuration uses a 16MB buffer, starts with a 200ms reconnection delay, and attempts up to 10 reconnections before logging an error.
Message Format Examples
RFC 3164 (BSD Syslog)
<14>Jun 17 14:30:45 gc-gateway gc_gateway:[runtime_1] Starting plugin<14>is the PRI (Priority): facility * 8 + severity- Facility 1 (user-level) + Severity 6 (info) = 1*8 + 6 = 14
RFC 5424 (Structured Syslog)
<14>1 2026-08-17T14:30:45.123Z gc-gateway gc_gateway - - - [gc_gateway@12345 plugin="runtime_1"] Starting plugin<14>1is the PRI and version- ISO 8601 timestamp
- Structured data includes plugin information
Syslog Facilities
| Value | Keyword | Description |
|---|---|---|
| 0 | kern | Kernel messages |
| 1 | user | User-level messages (default) |
| 2 | Mail system | |
| 3 | daemon | System daemons |
| 4 | auth | Security messages |
| 9 | cron | Cron daemon |
| 16-23 | local0-local7 | Local use |
Syslog Severities
| Value | Keyword | Description |
|---|---|---|
| 0 | emerg | System unusable |
| 1 | alert | Immediate action needed |
| 2 | crit | Critical conditions |
| 3 | err | Error conditions |
| 4 | warning | Warning conditions |
| 5 | notice | Normal but significant |
| 6 | info | Informational (default) |
| 7 | debug | Debug messages |
Architecture
Data Flow
The syslog forwarding feature integrates seamlessly with the existing log service architecture:
Client → [TCP Writer] → Log Processing
├──→ Log Store (CSV Files) [if storage_mode ≠ syslog]
└──→ Syslog Forwarder → Syslog Server [if storage_mode ≠ local]For UDP protocol, messages are sent directly to the syslog server immediately.
For TCP and TLS protocols, messages are:
- Queued in the message buffer
- Sent by a background worker task
- Automatically retried with exponential backoff if the connection fails
Background Worker (TCP/TLS)
The syslog forwarder spawns a dedicated background worker task for TCP and TLS protocols that:
- Continuously processes messages from the buffer
- Establishes and maintains the connection to the syslog server
- Automatically reconnects when the connection is lost
- Verifies connection health after each write operation
- Re-queues messages at the front of the buffer if sending fails
This ensures non-blocking operation - the log service can continue receiving and processing logs even when the syslog server is temporarily unavailable.
Severity Mapping
NextGen Gateway log levels are mapped to syslog severities as follows:
| NextGen Level | Syslog Severity | Value |
|---|---|---|
| Error | ERR | 3 |
| Warn | WARNING | 4 |
| Info | INFO | 6 |
| Debug | DEBUG | 7 |
| Trace | DEBUG | 7 |
Security Considerations
TLS Configuration
- Use TLS 1.2 or higher (default)
- Verify server certificates in production environments
- Protect private keys with appropriate file permissions (0600)
- Feature flag: TLS support requires the
tlsfeature to be enabled when building the service
Note: The
gc_log_servicebinary must be built with the--features tlsflag to enable TLS protocol support. Without this feature, selecting the TLS protocol will result in a warning message and no forwarding.
Message Sanitization
- Newlines (
\n), carriage returns (\r), and null bytes (\0) are automatically removed from messages - This prevents syslog injection attacks
Network Security
- Use firewall rules to restrict access to the syslog port
- Consider IP allowlisting for syslog servers
- Use dedicated VLANs for logging traffic in secure environments
Performance Considerations
| Protocol | Characteristics | Use Case |
|---|---|---|
| UDP | Fast, no connection overhead, unreliable | High-volume, loss-tolerant logging |
| TCP | Reliable, connection-oriented, slightly slower | Guaranteed delivery required |
| TLS | Encrypted, reliable, highest overhead | Secure environments requiring encryption |
Error Handling
Connection Failures
The Log Service implements robust error handling for syslog forwarding:
- TCP and TLS connections use exponential backoff retry with configurable parameters
- Base delay: 100ms by default, doubles on each retry (100ms, 200ms, 400ms, 800ms, 1600ms)
- Maximum attempts: 5 retries by default before logging an error
- Failed connections are logged with warning messages
- Connection health verification: After each write, the service verifies the connection is still alive by attempting a small read with timeout
Message Buffering (TCP/TLS only)
For TCP and TLS protocols, the Log Service implements a message buffer to handle temporary network issues:
- Messages are queued in memory when the syslog server is unavailable
- Buffer size: Configurable, default is 8MB (approximately 80,000 messages at 100 bytes each)
- When the buffer is full, oldest messages are dropped to make room for new ones
- The background worker continuously attempts to send buffered messages with automatic reconnection
- Once the connection is restored, all buffered messages are sent in order
Behavior by Storage Mode
| Error | Storage Mode | Behavior |
|---|---|---|
| Syslog server down | local |
Ignore (continue logging locally) |
| Syslog server down | syslog |
Queue messages in buffer, retry with backoff |
| Syslog server down | both |
Queue messages in buffer AND continue local storage |
| Buffer full | syslog or both |
Drop oldest messages, log error, continue accepting new messages |
| Message too long | any | Truncate to 8192 bytes (RFC 5424 recommendation) |
| Connection broken | syslog or both |
Detect via write/read failure, reconnect automatically |
Troubleshooting
Syslog Messages Not Appearing
- Check syslog server is running:
systemctl status rsyslog(or your syslog daemon) - Check network connectivity:
telnet logserver 514ornc -zv logserver 514 - Check firewall rules: Ensure the gateway can reach the syslog server
- Check server accepts connections: Verify the syslog server is configured to accept connections from the gateway’s IP
- Test manually:
echo "<14>Test" | nc -u logserver 514
TLS Connection Failures
- Check TLS is enabled: Ensure the
--syslog-protocol tlsoption is set - Check certificates: Verify CA certificate, client cert, and key paths are correct
- Check certificate validity: Ensure certificates are not expired
- Check server certificate: Verify the server certificate is trusted by the CA
- Test with openssl:
openssl s_client -connect logserver:6514 -CAfile /path/to/ca.pem
Connection Refused
- Check syslog server is running: Verify the syslog daemon is active
- Check port is listening:
netstat -tulnp | grep 514orss -tulnp | grep 514 - Check server accepts remote connections: Some syslog servers only listen on localhost by default
Invalid Configuration
- Check facility value: Must be between 0 and 23
- Check port value: Must be between 1 and 65535
- Check protocol value: Must be
udp,tcp, ortls - Check format value: Must be
rfc3164orrfc5424 - TLS protocol requires certificates: If using TLS, ensure certificate paths are provided
Buffer Full Warnings
- Check buffer size: If you see “Buffer full” messages, increase
syslog_buffer_bytes - Check syslog server availability: The syslog server may be down or overloaded
- Check network connectivity: Ensure the gateway can reach the syslog server
- Increase buffer size: For high-volume environments, consider increasing to 16MB or 32MB
- Use both mode: To prevent log loss, use
storage_mode=bothso logs are stored locally even if syslog forwarding fails
Migration Guide
For Existing Deployments
No changes required for existing deployments using local storage only. The syslog forwarding feature is completely optional and disabled by default.
Enabling Syslog Forwarding
To enable syslog forwarding for an existing deployment:
-
Add syslog configuration to your service startup:
gc_log_service \ --storage-mode both \ --syslog-address logserver.local \ --syslog-port 514 -
Or use environment variables:
export GC_LOG_STORAGE_MODE=both export GC_LOG_SYSLOG_ADDRESS=logserver.local export GC_LOG_SYSLOG_PORT=514 -
Restart the service:
systemctl restart gc_log_service
Rollback
If you need to rollback to a version without syslog support:
- Stop the new service
- Reinstall the previous version
- Start the service
Note: If you were using storage_mode = syslog, logs were NOT stored locally. Rolling back may result in lost logs that were sent during the new version’s operation.