Helpers
A few helper functions for dealing with log levels, severities and so on.
get_syslog_pri_part ¶
get_syslog_pri_part(log_level: int, facility: int = USER) -> str
Returns a syslog PRI prefix from the provided log level and facility.
See the relevant section of
RFC 3164
for details about syslog standard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_level |
int
|
A Python log level number. The corresponding severity value will
be determined via the
|
required |
facility |
int
|
The |
USER
|
Returns:
| Type | Description |
|---|---|
str
|
A string of the PRI value enclosed in angle brackets. |
Examples:
>>> import logging
>>> get_syslog_pri_part(logging.INFO)
<14>
>>> from syslogformat.facility import KERNEL
>>> get_syslog_pri_part(logging.DEBUG, KERNEL)
<7>
normalize_log_level ¶
normalize_log_level(level: int | str) -> int
Returns an integer that can be interpreted as a log level number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level |
int | str
|
If passed an integer, that value is returned unchanged.
If passed a string, the corresponding level number is looked up in
the level-name-mapping of the |
required |
Returns:
| Type | Description |
|---|---|
int
|
Valid log level number. |
Raises:
| Type | Description |
|---|---|
InvalidLogLevel
|
If |
Examples:
>>> normalize_log_level(42)
42
>>> normalize_log_level("WARNING")
30