libsyslog/lib.rs
1//! This crate provides an API implementing the standard Rust logging facade
2//! to the system's syslog. That is, it implements the [Log][log::Log] trait
3//! of the [log] crate for native syslog (the one typically implemented in C
4//! and residing in libc).
5//!
6//! Syslog needs to be initialized prior to any [logging macros][log#macros]
7//! being called. That is usally done through a single chained call of its
8//! [builder][Syslog::builder], with optional
9//! [methods][SyslogBuilder#implementations] to customize the logger before
10//! finalizing the setup by calling [build][SyslogBuilder::build] and
11//! [init][Syslog::init].
12//!
13//! Typical use: (A.k.a. recommended snippet to copy'n'paste to the start of
14//! `main()` of your daemon.)
15//! ```
16//! # use log::error;
17//! # fn main() -> Result<(), log::SetLoggerError> {
18//! libsyslog::Syslog::builder()
19//! .module_level(std::module_path!(), log::LevelFilter::Info)
20//! .level(log::LevelFilter::Off)
21//! .build()
22//! .init()?;
23//!
24//! error!("Hello libsyslog. I've failed you.");
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! It is likely reasonable for most users to configure the
30//! [module_level][SyslogBuilder::module_level] and
31//! [level][SyslogBuilder::level] filters to only have the application's own
32//! log messages sent to syslog (ignoring potentially chatty libraries), as in
33//! the above example.
34//!
35//! The scope of this crate is limited as described by the very first paragraph
36//! above. Its intended use is during normal operation, in software with modest
37//! requirements on low frequency logging. Note that syslog risks killing
38//! performance. Consider using another additional facade, in combination with
39//! a `--no-daemon` option, for when developing and debugging. And please
40//! remember, if [libsyslog][`crate`] does not meet your requirements, there
41//! are plenty of other crates for logging around.
42
43// According to [doc][], syslog() and friends are not thread safe on AIX. It
44// appears there is a family or related functions with an _r suffix which
45// should likely be used instead. Patches for adding AIX support are welcome.
46//
47// It should of course possible to locally disable the check below, but then
48// it's up to you to ensure your application is single threaded.
49//
50#[cfg(target_os = "aix")]
51compile_error!("AIX user, please help with the code comment above this error.");
52//
53// [doc]: https://www.ibm.com/docs/en/aix/latest?topic=s-syslog-openlog-closelog-setlogmask-subroutine
54
55mod builder;
56mod facility;
57#[cfg(feature = "bitflags")]
58mod logopt;
59mod syslog;
60
61#[cfg(test)]
62mod tests;
63
64#[cfg(feature = "bitflags")]
65pub use logopt::*;
66
67pub use {
68 builder::*,
69 facility::*,
70 syslog::*,
71};