Crates.io | slog-syslog5424 |
lib.rs | slog-syslog5424 |
version | 0.1.1 |
source | src |
created_at | 2018-09-03 05:49:20.927445 |
updated_at | 2018-09-03 05:52:13.621795 |
description | RFC5424 implementation for slog |
homepage | https://github.com/nocduro/slog-syslog5424 |
repository | https://github.com/nocduro/slog-syslog5424 |
max_upload_size | |
id | 82703 |
size | 125,271 |
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.
slog-async
to avoid slowing down the main threadslog-retry
useful.Building formatting struct: https://docs.rs/syslog5424
slog
implementation: https://docs.rs/slog-syslog5424
#[macro_use]
extern crate slog;
extern crate slog_syslog5424;
use slog_syslog5424::{Facility, Rfc5424Builder, Rfc5424Writer, WriteFormat};
use slog::Drain;
use std::sync::Mutex;
fn main() {
let w = std::io::stderr();
let formatter = Rfc5424Builder::new("enterprise_id", Facility::User)
.app_name("myapp")
.expect("invalid app name")
.hostname("192.0.2.1")
.expect("invalid hostname")
.pid("8710")
.expect("invalid pid")
.write_format(WriteFormat::RFC5424)
.build();
let rfc5424_writer = Rfc5424Writer::new(w, formatter);
let root = slog::Logger::root(
Mutex::new(rfc5424_writer).map(slog::Fuse),
o!("version" => env!("CARGO_PKG_VERSION")),
);
info!(root, "service started");
let sub_log = root.new(o!("address" => "example.com", "port" => "54201"));
warn!(sub_log, "tls disabled!");
info!(sub_log, "starting download");
info!(sub_log, "download complete");
}
sandbox-master/telegraf/telgraf.conf
: add the following:[[inputs.syslog]]
server = "tcp://:6514"
sandbox-master/docker-compose.yml
modify the ports exposed for the telegraf
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
./sandbox up
TcpStream
AND format in RFC5425:#[macro_use]
extern crate slog;
extern crate slog_syslog5424;
use slog_syslog5424::{Facility, Rfc5424Builder, Rfc5424Writer, WriteFormat};
use slog::Drain;
use std::sync::Mutex;
use std::net::TcpStream;
fn main() {
let w = TcpStream::connect("127.0.0.1:6514").unwrap();
let formatter = Rfc5424Builder::new("enterprise_id", Facility::User)
.app_name("myapp")
.expect("invalid app name")
.hostname("192.0.2.1")
.expect("invalid hostname")
.pid("8710")
.expect("invalid pid")
.write_format(WriteFormat::RFC5425) // telegraf only likes 5425
.build();
let rfc5424_writer = Rfc5424Writer::new(w, formatter);
let root = slog::Logger::root(
Mutex::new(rfc5424_writer).map(slog::Fuse),
o!("version" => env!("CARGO_PKG_VERSION")),
);
info!(root, "service started");
let sub_log = root.new(o!("address" => "example.com", "port" => "54201"));
warn!(sub_log, "tls disabled!");
info!(sub_log, "starting download");
info!(sub_log, "download complete");
}
Doesn't use any specific OS controls, so should work on everything. Just substitute the required writer for your system.
MIT