[systemd-devel] Journald logging handler for Python 3 and AsyncIO integration

Jörg Thalheim joerg.systemd at higgsboson.tk
Sat May 2 08:22:49 PDT 2015


On Sat, 2 May 2015 16:31:44 +0200
Ludovic Gasc <gmludo at gmail.com> wrote:

> 2015-05-02 16:18 GMT+02:00 Zbigniew Jędrzejewski-Szmek
> <zbyszek at in.waw.pl>:
> 
> > On Sat, May 02, 2015 at 03:34:52PM +0200, Ludovic Gasc wrote:
> > > Ok, my bad, I didn't see JournalHandler class to use with Python
> > > logging:
> > >
> > http://www.freedesktop.org/software/systemd/python-systemd/journal.html#journalhandler-class
> > >
> > > Nevertheless, my question about communication between Python and
> > > journald remains.
> > Can you rephrase the question? I don't quite understand what
> > functionality you're missing from
> >
> > http://www.freedesktop.org/software/systemd/python-systemd/journal.html#systemd.journal.send
> > .
> >
> >
> In AsyncIO, when you interact with the outside world, you need to use
> "yield from", for example:
> https://docs.python.org/3/library/asyncio-stream.html#tcp-echo-client-using-streams
> 
> "yield from" means to the Python interpreter to "pause" the coroutine
> to work on another coroutine until data arrive.
> To be efficient, I/O should handled by AsyncIO, even if some
> workarounds are possible if the raw socket isn't accessible.
> 
> If this pattern is useful for HTTP requests, for logging where you
> shouldn't wait a return, it isn't very critical, especially if you use
> syslog protocol with UNIX socket.
> 
> Nevertheless, to be sure, I wish to understand how the communication
> works between my process and journald daemon.

AsyncIO was not their, when these bindings were written. Inventing a
asynchron API on top of a synchron API (as provided by sd_journal_sendv) might be hard.
So I have two ideas here:

1. use a background thread, which writes messages to journald from a ring buffer and fill this ringbuffer from your application.
2. write to the unix socket /run/systemd/journal/socket directly with python and asyncIO, 
   this is not as hard as it sounds because it is still some kind of text protocol. The coreos guys did this in go here:
   https://github.com/coreos/go-systemd/blob/master/journal/send.go#L68
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 603 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150502/afe70548/attachment.sig>


More information about the systemd-devel mailing list