Skip to content

Instantly share code, notes, and snippets.

@marvin
Created June 9, 2011 19:16
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save marvin/1017480 to your computer and use it in GitHub Desktop.
Save marvin/1017480 to your computer and use it in GitHub Desktop.
syslog calculate facility and severity from PRI(priority)
example:
PRI = 191
To get the Facility
Divide the PRI number by 8.
191/8 = 23.875
The whole number part is the facility.
To get the Severity
Take the whole number part 23 and multiply by 8 and the product subtract from 191:
191 - (23 * 8 )= 7
PRI = Facility 23 and Priority (7)
Work backword to check our work:
23*8 = 184 + 7 = 191
syslog severity overview
Numerical Severity
Code
0 Emergency: system is unusable
1 Alert: action must be taken immediately
2 Critical: critical conditions
3 Error: error conditions
4 Warning: warning conditions
5 Notice: normal but significant condition
6 Informational: informational messages
7 Debug: debug-level messages
Numerical Facility
Code
0 kernel messages
1 user-level messages
2 mail system
3 system daemons
4 security/authorization messages (note 1)
5 messages generated internally by syslogd
6 line printer subsystem
7 network news subsystem
8 UUCP subsystem
9 clock daemon (note 2)
10 security/authorization messages (note 1)
11 FTP daemon
12 NTP subsystem
13 log audit (note 1)
14 log alert (note 1)
15 clock daemon (note 2)
16 local use 0 (local0)
17 local use 1 (local1)
18 local use 2 (local2)
19 local use 3 (local3)
20 local use 4 (local4)
21 local use 5 (local5)
22 local use 6 (local6)
23 local use 7 (local7)
@marvin
Copy link
Author

marvin commented Jun 9, 2011

@andrewr123
Copy link

Or perhaps use masking and bitshifting? C psuedo-code follows:

severity = priority & 0x07;
facility = priority >> 3;

@quantenschaum
Copy link

or modulo and floor division
python example

p=191
s=p%8
f=p//8
print(s,f)
# yields 7 23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment