slog-syslog5424
- implementation of RFC5424 for slog
This crate provides a way for slog
to format its structured messages into the syslog 5424 format which preserves structure.
The output is written to a type provided by the user that implements the Write
trait.
For the underlying syslog5424 crate, check here.
Notes
- Should almost always be used with
slog-async
to avoid slowing down the main thread - When sending to remote syslog servers (like InfluxDB) the format should be set to RFC5425 to include the length in the message. A TLS writer should ideally also be used.
- When logging directly to a remote syslog server you may find
slog-retry
useful.
Crate Documentation
Building formatting struct: https://docs.rs/syslog5424
slog
implementation: https://docs.rs/slog-syslog5424
Examples
Basic logging to stderr
extern crate slog;
extern crate slog_syslog5424;
use ;
use Drain;
use Mutex;
Logging to InfluxDB
- Download InfluxDB sandbox: https://github.com/influxdata/sandbox
- configure telegraf to enable syslog input:
- in
sandbox-master/telegraf/telgraf.conf
: add the following:
server = "tcp://:6514"
- in
sandbox-master/docker-compose.yml
modify the ports exposed for thetelegraf
container:
telegraf: # Full tag list: https://hub.docker.com/r/library/telegraf/tags/ image: telegraf:latest environment: HOSTNAME: "telegraf-getting-started" # Telegraf requires network access to InfluxDB links: - influxdb volumes: # Mount for telegraf configuration - ./telegraf/:/etc/telegraf/ # Mount for Docker API access - /var/run/docker.sock:/var/run/docker.sock ports: - "6514:6514/tcp" depends_on: - influxdb
- in
- Start containers:
./sandbox up
- Modify previous example code to use
TcpStream
AND format in RFC5425:
extern crate slog;
extern crate slog_syslog5424;
use ;
use Drain;
use Mutex;
use TcpStream;
- view your results in chronograf: http://localhost:8888/logs
OS support
Doesn't use any specific OS controls, so should work on everything. Just substitute the required writer for your system.
License
MIT