File: test_syslog.rs

package info (click to toggle)
rust-nix 0.30.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,248 kB
  • sloc: ansic: 18; makefile: 7
file content (39 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![cfg(feature = "syslog")]
use nix::syslog::{openlog, syslog, Facility, LogFlags, Severity};

#[test]
fn test_syslog_hello_world() {
    let flags = LogFlags::LOG_PID;

    #[cfg(not(target_os = "linux"))]
    openlog(None::<&str>, flags, Facility::LOG_USER).unwrap();
    #[cfg(target_os = "linux")]
    openlog(None, flags, Facility::LOG_USER).unwrap();

    syslog(Severity::LOG_EMERG, "Hello, nix!").unwrap();
    let name = "syslog";
    syslog(Severity::LOG_NOTICE, &format!("Hello, {name}!")).unwrap();
}

#[test]
#[cfg(target_os = "linux")]
fn test_openlog_with_ident() {
    use std::ffi::CStr;

    const IDENT: &CStr = unsafe {
        CStr::from_bytes_with_nul_unchecked(b"test_openlog_with_ident\0")
    };

    let flags = LogFlags::LOG_PID;
    openlog(Some(IDENT), flags, Facility::LOG_USER).unwrap();
    syslog(Severity::LOG_EMERG, "Hello, ident!").unwrap();
}

#[test]
#[cfg(not(target_os = "linux"))]
fn test_openlog_with_ident() {
    let flags = LogFlags::LOG_PID;
    openlog(Some("test_openlog_with_ident"), flags, Facility::LOG_USER)
        .unwrap();
    syslog(Severity::LOG_EMERG, "Hello, ident!").unwrap();
}