fix: journald compatible log level

This commit is contained in:
Daniel Langbein 2023-11-20 12:03:15 +01:00
parent ba358d244e
commit b9832d0b24
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
2 changed files with 15 additions and 9 deletions

View File

@ -3,7 +3,7 @@
[metadata]
name = de.p1st.monitor
version = 0.11.4
version = 0.11.5
author = Daniel Langbein
author_email = daniel@systemli.org
description = periodically monitor and warn

View File

@ -15,32 +15,38 @@ import sys
# define SD_DEBUG "<7>" /* debug-level messages */
def print_emerg(message: object):
print(f'<0> {message}', file=sys.stderr)
do_print('<0> ', message, file=sys.stderr)
def print_alert(message: object):
print(f'<1> {message}', file=sys.stderr)
do_print('<1> ', message, file=sys.stderr)
def print_crit(message: object):
print(f'<2> {message}', file=sys.stderr)
do_print('<2> ', message, file=sys.stderr)
def print_err(message: object):
print(f'<3> {message}', file=sys.stderr)
do_print('<3> ', message, file=sys.stderr)
def print_warning(message: object):
print(f'<4> {message}', file=sys.stderr)
do_print('<4> ', message, file=sys.stderr)
def print_notice(message: object):
print(f'<5> {message}', file=sys.stdout)
do_print('<5> ', message)
def print_info(message: object):
print(f'<6> {message}', file=sys.stdout)
do_print('<6> ', message)
def print_debug(message: object):
print(f'<7> {message}', file=sys.stdout)
do_print('<7> ', message)
def do_print(line_prefix: str, message: object, file=sys.stdout) -> None:
# Prefix each line in str(object) with `line_prefix`.
prefixed = line_prefix + str(message).replace('\n', '\n' + line_prefix)
print(prefixed, file=file)