Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 1.21 KB

log-syslog.zh.md

File metadata and controls

35 lines (28 loc) · 1.21 KB

登录到 Unix 系统日志

[![log-badge]][log] [![syslog-badge]][syslog] [![cat-debugging-badge]][cat-debugging]

将消息记录到UNIX 系统日志。用syslog::init初始化记录器后端。 syslog::Facility表明该程序,添加的日志条目分类,log::LevelFilter表示允许的日志等级,和Option<&str>持有可选的应用程序名称。

#[macro_use]
extern crate log;
# #[cfg(target_os = "linux")]
extern crate syslog;

# #[cfg(target_os = "linux")]
use syslog::{Facility, Error};

# #[cfg(target_os = "linux")]
fn main() -> Result<(), Error> {
    syslog::init(Facility::LOG_USER,
                 log::LevelFilter::Debug,
                 Some("My app name"))?;
    debug!("this is a debug {}", "message");
    error!("this is an error!");
    Ok(())
}

# #[cfg(not(target_os = "linux"))]
# fn main() {
#     println!("So far, only Linux systems are supported.");
# }