syslog_tls/
facility.rs

1use std::str::FromStr;
2
3#[allow(non_camel_case_types)]
4#[derive(Copy, Clone, Debug)]
5pub enum Facility {
6    LOG_KERN = 0 << 3,
7    LOG_USER = 1 << 3,
8    LOG_MAIL = 2 << 3,
9    LOG_DAEMON = 3 << 3,
10    LOG_AUTH = 4 << 3,
11    LOG_SYSLOG = 5 << 3,
12    LOG_LPR = 6 << 3,
13    LOG_NEWS = 7 << 3,
14    LOG_UUCP = 8 << 3,
15    LOG_CRON = 9 << 3,
16    LOG_AUTHPRIV = 10 << 3,
17    LOG_FTP = 11 << 3,
18    LOG_LOCAL0 = 16 << 3,
19    LOG_LOCAL1 = 17 << 3,
20    LOG_LOCAL2 = 18 << 3,
21    LOG_LOCAL3 = 19 << 3,
22    LOG_LOCAL4 = 20 << 3,
23    LOG_LOCAL5 = 21 << 3,
24    LOG_LOCAL6 = 22 << 3,
25    LOG_LOCAL7 = 23 << 3,
26}
27
28impl FromStr for Facility {
29    type Err = ();
30    fn from_str(s: &str) -> Result<Facility, ()> {
31        let result = match &s.to_lowercase()[..] {
32            "log_kern" | "kern" => Facility::LOG_KERN,
33            "log_user" | "user" => Facility::LOG_USER,
34            "log_mail" | "mail" => Facility::LOG_MAIL,
35            "log_daemon" | "daemon" => Facility::LOG_DAEMON,
36            "log_auth" | "auth" => Facility::LOG_AUTH,
37            "log_syslog" | "syslog" => Facility::LOG_SYSLOG,
38            "log_lpr" | "lpr" => Facility::LOG_LPR,
39            "log_news" | "news" => Facility::LOG_NEWS,
40            "log_uucp" | "uucp" => Facility::LOG_UUCP,
41            "log_cron" | "cron" => Facility::LOG_CRON,
42            "log_authpriv" | "authpriv" => Facility::LOG_AUTHPRIV,
43            "log_ftp" | "ftp" => Facility::LOG_FTP,
44            "log_local0" | "local0" => Facility::LOG_LOCAL0,
45            "log_local1" | "local1" => Facility::LOG_LOCAL1,
46            "log_local2" | "local2" => Facility::LOG_LOCAL2,
47            "log_local3" | "local3" => Facility::LOG_LOCAL3,
48            "log_local4" | "local4" => Facility::LOG_LOCAL4,
49            "log_local5" | "local5" => Facility::LOG_LOCAL5,
50            "log_local6" | "local6" => Facility::LOG_LOCAL6,
51            "log_local7" | "local7" => Facility::LOG_LOCAL7,
52            _ => return Err(()),
53        };
54        Ok(result)
55    }
56}
57
58impl Default for Facility {
59    /// Returns the default `Facility`, which is `LOG_USER` (as [specified by POSIX]).
60    ///
61    /// [specified by POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/closelog.html
62    fn default() -> Self {
63        Facility::LOG_USER
64    }
65}