Geal / rust-syslog

Send syslog messages from Rust
MIT License
109 stars 55 forks source link

Implement `Default` for formatters and `Facility`; get hostname automatically #51

Closed argv-minus-one closed 2 years ago

argv-minus-one commented 4 years ago

This PR implements Default for Facility, Formatter3164, and Formatter5424.

Motivation

Most of the Formatter* fields are about the host environment. The only one that the application really needs to fill in is facility. By implementing Default for Formatter*, constructing one is made much easier:

let formatter = syslog::Formatter3164 {
  facility: syslog::Facility::LOG_DAEMON,
  ..Default::default()
};

Defaults

The default Facility is LOG_USER, as specified by POSIX.

Formatter defaults are as follows:

syslog::init

In addition to the Default implementations, the init function now fills in the hostname in the same way.

Dependencies & MSRV

This PR adds a dependency on the hostname crate.

This PR does not change the minimum supported Rust version of this crate, which appears to be 1.31. (Even without this PR, this crate fails to build on Rust ≤ 1.30.)

Geal commented 2 years ago

great idea, thanks