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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// This file is part of dpdk. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/dpdk/master/COPYRIGHT. No part of dpdk, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
// Copyright © 2016-2019 The developers of dpdk. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/dpdk/master/COPYRIGHT.
//


/// Represents a DPDK syslog priority.
///
/// Defaults to `debug` for debug builds and `warning` for production builds.
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
#[derive(Serialize, Deserialize)]
#[allow(missing_docs)]
#[repr(i32)]
pub enum SyslogPriority
{
	emergency = LOG_EMERG,
	alert = LOG_ALERT,
	critical = LOG_CRIT,
	error = LOG_ERR,
	warning = LOG_WARNING,
	notice = LOG_NOTICE,
	info = LOG_INFO,
	debug = LOG_DEBUG,
}

impl Default for SyslogPriority
{
	#[inline(always)]
	fn default() -> Self
	{
		use self::SyslogPriority::*;
		
		if cfg!(debug_assertions)
		{
			debug
		}
		else
		{
			warning
		}
	}
}

impl SyslogPriority
{
	/// As an initialization argument for DPDK.
	#[inline(always)]
	pub fn as_initialization_argument(self) -> ConstCStr
	{
		use self::SyslogPriority::*;
		
		match self
		{
			emergency => ConstCStr(b"emergency\0"),
			alert => ConstCStr(b"alert\0"),
			critical => ConstCStr(b"critical\0"),
			error => ConstCStr(b"error\0"),
			warning => ConstCStr(b"warning\0"),
			notice => ConstCStr(b"notice\0"),
			info => ConstCStr(b"info\0"),
			debug => ConstCStr(b"debug\0"),
		}
	}
	
	#[inline(always)]
	pub(crate) fn log_upto(self) -> i32
	{
		(1 << ((self as i32) + 1)) - 1
	}
}