pub struct Syslog {
pub facility: Facility,
pub process: Option<String>,
pub hostname: Option<String>,
pub level: Level,
pub proto: SyslogProto,
pub server: Option<SyslogAddr>,
pub timeout: Duration,
}syslog only.Expand description
Config for syslog output, supports local and remote server.
The underlayer protocol is implemented by syslog crate, currently Formatter3164 is adapted.
In order to achieve efficient socket I/O, the message is sent to channel, and asynchronous flushed by backend writer.
When your program shutting down, should call flush to ensure the log is written to the socket.
log::logger().flush();On panic, our panic hook will call flush() explicitly.
On connection, will output “syslog connected” message to stdout.
On remote syslog server failure, will not panic, only “syslog: flush err” message will be print to stderr, the backend thread will automatically reconnect to server. In order to prevent hang up, the message will be dropped after a timeout.
§Example connecting local server
Source of crate::recipe::syslog_local()
use captains_log::*;
pub fn syslog_local(max_level: Level) -> Builder {
let syslog = Syslog::new(Facility::LOG_USER, max_level);
return Builder::default().syslog(syslog);
}§Example connecting remote server
use captains_log::*;
let syslog = Syslog::new(Facility::LOG_USER, Level::Info).tcp("10.10.0.1:601");
let _ = Builder::default().syslog(syslog).build();Fields§
§facility: FacilitySyslog facility
process: Option<String>Auto filled current process
hostname: Option<String>Auto filled localhost,
level: Levelmax level of message goes to syslog
proto: SyslogProtoWhen in doubt, use RFC3164
server: Option<SyslogAddr>When None, connect local default unix socket.
timeout: DurationDrop msg when syslog server fail after a timeout, also apply to tcp connect timeout.
Implementations§
Source§impl Syslog
impl Syslog
pub fn new(facility: Facility, level: Level) -> Self
pub fn timeout(self, d: Duration) -> Self
Sourcepub fn process_name(self, name: String) -> Self
pub fn process_name(self, name: String) -> Self
Set process name if you don’t want the default