Skip to content

Severity

Numerical codes for syslog severities.

These constants in this module correspond to those defined in section 4.1.1 of RFC 3164.

EMERGENCY module-attribute

EMERGENCY = 0

System is unusable

ALERT module-attribute

ALERT = 1

Action must be taken immediately

CRITICAL module-attribute

CRITICAL = 2

Critical conditions

ERROR module-attribute

ERROR = 3

Error conditions

WARNING module-attribute

WARNING = 4

Warning conditions

NOTICE module-attribute

NOTICE = 5

Normal but significant condition

INFORMATIONAL module-attribute

INFORMATIONAL = 6

Informational messages

DEBUG module-attribute

DEBUG = 7

Debug-level messages

log_level_severity

log_level_severity(level_num: int) -> int

Returns corresponding the syslog severity for a given Python log level.

Details about the meaning of the numerical severity values can be found in section 4.1.1 of RFC 3164. Even though there are more codes available to syslog, the EMERGENCY and NOTICE codes are never returned here, i.e. it goes straight from INFORMATIONAL to WARNING because there is no equivalent log level in the Python logging module to NOTICE, and EMERGENCY is unnecessary because no Python script should be able to cause such severe problems. Therefore any number above logging.CRITICAL passed will result in ALERT being returned.

Parameters:

Name Type Description Default
level_num int

An integer representing a Python log level number

required

Returns:

Type Description
int

One of the predefined severity codes that matches the given log level

Examples:

>>> import logging
>>> log_level_severity(logging.DEBUG)
7
>>> log_level_severity(logging.CRITICAL)
2
>>> log_level_severity(logging.CRITICAL + 1)
1
>>> log_level_severity(999_999)
1