Expand description

The syslog transport layer

Introduction

This module defines the Transport trait that all implementations must support, as well as the UDP, TCP & Unix socket (datagram as well as stream) implementations.

Examples

To send syslog messages over UDP to a daemon listening on port 514 (the default) on localhost:

use tracing_rfc_5424::transport::UdpTransport;
let transpo = UdpTransport::local().unwrap();

On a non-standard port on another host:

use tracing_rfc_5424::transport::UdpTransport;
let transpo = UdpTransport::new("some-host.domain.io:5514");
assert!(transpo.is_err()); // no such host, after all

To send messages over UDP to a local Unix socket:

use tracing_rfc_5424::transport::UnixSocket;
let transpo = UnixSocket::new("/i/am/not/there.s");
assert!(transpo.is_err()); // no such socket, after all

Discussion

Why not just implement std::io::Write (and tokio::io::AsyncWrite)? Because the abstraction doesn’t make sense for us; std::io::Write is an abstraction for a general-purpose, byte-oriented sink. “The write method will attempt to write some data into the object, returning how many bytes were successfully written.” Our semantics are different: “take this serialized message & transmit it to the syslog daemon”.

tracing_subscriber::Layer is synchronous, but I could, I suppose, provide an async Transport abstraction, enabling someone to write:

async fn f(&self, msg: &str) {
    self.syslog_formatter.on_msg(msg)?)
        .and_then(|thing| self.transport.send(thing).await?)
}

Structs

Enums

  • syslog transport layer errors

Traits

  • Operations all transport layers must support.

Type Definitions