[systemd-devel] Native journald logging for Python

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Tue Jun 26 08:31:14 PDT 2012


On 06/26/2012 10:31 AM, David Strauss wrote:
> I spent a bit of time on IRC earlier today trying to figure out how to
> log to journald fields using Python. Apparently, that requires use of
> the native journald C API.
> 
> So, I wrote the necessary glue:
> https://github.com/davidstrauss/journald-python
Hi,
seems like a useful thing. Just a couple of notes about the code itself:


#ifndef journaldpython
#define journaldpython
...
#endif

This is not a header file, so this wrapping doesn't seem useful.

PyObject *item = PyTuple_GetItem(args, i);
char * stritem = PyString_AsString(item);
iov[i].iov_base = stritem;
iov[i].iov_len = strlen(stritem);

I think that there's a problem here -- PyString_AsString will return
NULL if item is not a string. Also, using PyString_AsStringAndSize would
avoid the need to iterate over the memory with strlen.

So maybe something like:

if(PyString_AsStringAndSize(item, &iov[i].iov_base, &iov[i].iov_len))
  return NULL;

Have you thought about providing python3 compatibility? I could whip a
patch if you think it would be useful.

Zbyszek


More information about the systemd-devel mailing list