Supports Python versions 2.6 through 3.3 (tested on 2.7 and 3.2).
See JournalHandler docstring for usage details.
[zj: - use send() instead of using sendv() directly
- do exception handling like in the logging module
- bumped min version to python2.6, since the module
does not work with python2.5 anyway ]
A bare-bones wrapper is provided as _journald.stream_fd(),
and a more usable version as journald.stream().
Documentation is included. Tested under Python 2.7 and 3.2.
Allow UTF-8, and force encoding as UTF-8 if the payload is known to be
text. Under Python 3, this means that bytes payload is sent as-is, and
strings are encoded to UTF-8. Under Python 2, this means that unicode
payload is encoded to UTF-8, and the rest is sent as-is, because there
we are missing the extra information to distinguish text and binary data.
IOW, under Python 2, it is the responsibility of the called to provide
properly encoded payload, and under Python 3, there is extra hand-holding
which should help catch mistakes.
Fields which are certain to be text (MESSAGE, MESSAGE_ID, CODE_FILE,
CODE_FUNC) are text-only. The names of fields are text-only too. The
payload of other fields can be binary.
$python3 -c 'import journald; x = lambda: journald.send("tescik"); x()'
gives a message like:
MESSAGE=tescik
CODE_FILE=<string>
CODE_LINE=1
CODE_FUNC=<lambda>
_TRANSPORT=journal
...
This makes the CODE_* fields much more useful: before they would
always give the location of the sd_journald_sendv() call in the module
source, and now they specify the location of the caller of
journald.send().
When using the low-level journald.sendv() is becomes the
responsibility of the caller to specify the CODE_* fields.
journald.send() is renamed to journald.sendv(), and a replacement
journald.send() is added. This new function has a more pythonic API,
where one positional argument is used for the message, and keyword
arguments can be used to specify other fields.
Implementing argument parsing in C would be really painful, for little
gain, so a pure-python module is added, which provides send(), which
in turn calls sendv().