This is the python I am using.
$ python3 --version
Python 3.5.2
This is the test code after some googling (How to log to journald (systemd) via Python?). I am trying to use journal log.
#!/usr/bin/python3
import logging
from systemd.journal import JournalHandler
log = logging.getLogger('test')
log.addHandler(JournalHandler())
log.setLevel(logging.DEBUG)
log.warning("warn")
log.info("info")
log.error("error")
log.debug("debug")
I am expecting to see in the log something like:
WARNING: warn
INFO: info
ERROR: error
DEBUG: debug
But this is what actually shows:
Nov 22 09:29:56 host1 ./test_log.py[8997]: warn
Nov 22 09:29:56 host1 ./test_log.py[8997]: info
Nov 22 09:29:56 host1 ./test_log.py[8997]: error
Nov 22 09:29:56 host1 ./test_log.py[8997]: debug
There is no log level prefixing the log message. Thanks for the help.
More info,
I also try formatting.
logging.basicConfig(format='%(levelname)s %(message)s')
Then on stdout, I could see log level but still not in journal.