Created
June 15, 2021 20:44
-
-
Save moreati/5f12d177c0a5d6c4404df8d352d4b945 to your computer and use it in GitHub Desktop.
Demonstration of logging to systemd journal with offcial Python bindings, and cysystemd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import logging | |
log = logging.getLogger('systemd_demo') | |
log.setLevel(logging.DEBUG) | |
# Official bindings | |
import systemd.journal | |
systemd.journal.send( | |
"Hello systemd", | |
PRIORITY=systemd.journal.LOG_DEBUG, | |
SYSLOG_IDENTIFIER='systemd_demo', | |
) | |
handler = systemd.journal.JournalHandler(SYSLOG_IDENTIFIER='systemd_demo') | |
log.addHandler(handler) | |
log.debug('Hello systemd through logging framework') | |
log.removeHandler(handler) | |
handler.close() | |
# Cython bindings, by mosquito | |
import cysystemd.journal | |
cysystemd.journal.send( | |
message="Hello cysystemd", | |
priority=int(cysystemd.journal.Priority.DEBUG), | |
syslog_identifier='systemd_demo', | |
) | |
handler = cysystemd.journal.JournaldLogHandler(identifier='systemd_demo') | |
log.addHandler(handler) | |
log.debug('Hello cysystemd through logging framework') | |
log.removeHandler(handler) | |
handler.close() |
Author
moreati
commented
Jun 15, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment