Debian Codegraph @

third_party/rust/nix/test/test_syslog.rs

raw
1 use nix::syslog::{openlog, syslog, Facility, LogFlags, Severity};
2
3 #[test]
4 fn test_syslog_hello_world() {
5 let flags = LogFlags::LOG_PID;
6
7 #[cfg(not(target_os = "linux"))]
8 openlog(None::<&str>, flags, Facility::LOG_USER).unwrap();
9 #[cfg(target_os = "linux")]
10 openlog(None, flags, Facility::LOG_USER).unwrap();
11
12 syslog(Severity::LOG_EMERG, "Hello, nix!").unwrap();
13 let name = "syslog";
14 syslog(Severity::LOG_NOTICE, &format!("Hello, {name}!")).unwrap();
15 }
16
17 #[test]
18 #[cfg(target_os = "linux")]
19 fn test_openlog_with_ident() {
20 use std::ffi::CStr;
21
22 const IDENT: &CStr = unsafe {
23 CStr::from_bytes_with_nul_unchecked(b"test_openlog_with_ident\0")
24 };
25
26 let flags = LogFlags::LOG_PID;
27 openlog(Some(IDENT), flags, Facility::LOG_USER).unwrap();
28 syslog(Severity::LOG_EMERG, "Hello, ident!").unwrap();
29 }
30
31 #[test]
32 #[cfg(not(target_os = "linux"))]
33 fn test_openlog_with_ident() {
34 let flags = LogFlags::LOG_PID;
35 openlog(Some("test_openlog_with_ident"), flags, Facility::LOG_USER)
36 .unwrap();
37 syslog(Severity::LOG_EMERG, "Hello, ident!").unwrap();
38 }