A lightweight, efficient tool for forwarding log entries from a file to a syslog server in real-time, following the RFC 5424 syslog protocol standard.
- Real-time Log Forwarding: Monitors log files and forwards new entries as they appear
- Protocol Support: Supports both UDP and TCP transport protocols
- RFC 5424 Compliance: Formats messages according to the syslog standard
- File Rotation Handling: Automatically detects and adapts to log file rotations/truncations
- Connection Recovery: Automatically attempts to reconnect if TCP connections are lost
- Customizable Configuration: Easy JSON-based configuration
- Robust Error Handling: Comprehensive logging and graceful error recovery
- Command-line Options: Support for custom config paths and verbose logging
- Python 3.6 or higher
- No external dependencies beyond the Python standard library
-
Clone this repository:
git clone https://github.com/neplicate/syslog-forwarder.git cd syslog-forwarder
-
Create or modify the configuration file (see Configuration section)
The forwarder uses a JSON configuration file (config.json
by default) with the following parameters:
Parameter | Description | Default | Required |
---|---|---|---|
server_ip |
IP address of the syslog server | - | Yes |
server_port |
Port number of the syslog server | - | Yes |
log_file |
Path to the log file to monitor | - | Yes |
protocol |
Transport protocol (udp or tcp ) |
udp |
No |
facility |
Syslog facility code (0-23) | 1 (user-level) |
No |
severity |
Syslog severity code (0-7) | 6 (informational) |
No |
app_name |
Application name for syslog messages | syslog_forwarder |
No |
reconnect_delay |
Seconds to wait before reconnection attempts | 5 |
No |
read_delay |
Seconds to wait between file reads when idle | 0.1 |
No |
{
"server_ip": "10.0.0.1",
"server_port": 514,
"protocol": "tcp",
"log_file": "/var/log/application.log",
"facility": 1,
"severity": 6,
"app_name": "my_app",
"reconnect_delay": 5,
"read_delay": 0.1
}
Run the forwarder with the default configuration file:
python syslogserver.py
# Use a custom configuration file
python syslogserver.py --config /path/to/custom-config.json
# Enable verbose logging
python syslogserver.py --verbose
# Combine options
python syslogserver.py --config /path/to/custom-config.json --verbose
-
Start the forwarder:
python syslogserver.py
-
Add test messages to your log file:
echo "Test log message" >> logs.txt
-
Verify that messages appear on your syslog server
Messages are formatted according to RFC 5424 with the following structure:
<PRI>VERSION TIMESTAMP HOSTNAME APP-NAME PROCID MSGID STRUCTURED-DATA MSG
Where:
PRI
: Priority value calculated asfacility*8 + severity
VERSION
: Always 1 for RFC 5424TIMESTAMP
: ISO8601 format with UTC timezone (e.g.,2025-02-28T12:34:56.789Z
)HOSTNAME
: The hostname of the machine running the forwarderAPP-NAME
: The application name from configurationPROCID
: The process ID of the forwarderMSGID
: Not used (represented as-
)STRUCTURED-DATA
: Not used (represented as-
)MSG
: The log message content
For production deployments, consider the following:
- For sensitive logs, consider using TLS encryption for TCP connections
- Implement proper access controls on the log files and configuration
- Review and adjust syslog facility and severity levels according to your organization's policies
- For high-volume logs, UDP may offer better performance but without delivery guarantees
- Adjust the
read_delay
parameter based on log volume and system resources - Consider implementing batching for very high-volume environments
- Implement external monitoring of the forwarder process
- Consider setting up alerts for connection failures or other critical errors
-
Connection Refused
- Verify the syslog server IP and port
- Check firewall rules between the forwarder and server
- Verify the syslog server is running and accepting connections
-
Messages Not Appearing
- Check that the syslog server is configured to accept the facility/severity level you're using
- Verify the log file permissions allow the forwarder to read it
- Enable verbose logging for more detailed output
-
High CPU Usage
- Increase the
read_delay
parameter to reduce polling frequency - Check for very high log volume and consider optimizations
- Increase the
Contributions are welcome! Please feel free to submit pull requests or open issues to improve the functionality.
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add some amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.