Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function journal_print to wrap sd_journal_print #8

Merged
merged 1 commit into from
Mar 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions systemd/_journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ journal_sendv(PyObject *self, PyObject *args) {
return ret;
}

PyDoc_STRVAR(journal_journal_print__doc__,
"journal_print(priority, string) -> None\n\n"
"Print a string with priority to the system log.\n"
"Priority must be one of (LOG_EMERG, LOG_ALERT, LOG_CRIT, "
"LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)"
);

static PyObject*
journal_print(PyObject *self, PyObject *args) {
int err;
int priority;
const char *str;
if(!PyArg_ParseTuple(args, "is:journal_print",
&priority, &str))
return NULL;

err = sd_journal_print(priority, str);
if (err != 0) {
PyErr_Format(PyExc_RuntimeError, "Error from sd_journal_print: %d",
err);
return NULL;
}

Py_INCREF(Py_None);
return Py_None;
}

PyDoc_STRVAR(journal_stream_fd__doc__,
"stream_fd(identifier, priority, level_prefix) -> fd\n\n"
"Open a stream to journal by calling sd_journal_stream_fd(3)."
Expand All @@ -102,8 +129,9 @@ journal_stream_fd(PyObject *self, PyObject *args) {

static PyMethodDef methods[] = {
{"sendv", journal_sendv, METH_VARARGS, journal_sendv__doc__},
{"stream_fd", journal_stream_fd, METH_VARARGS,
journal_stream_fd__doc__},
{"stream_fd", journal_stream_fd, METH_VARARGS, journal_stream_fd__doc__},
{"journal_print", journal_print, METH_VARARGS,
journal_journal_print__doc__},
{NULL, NULL, 0, NULL} /* Sentinel */
};

Expand Down
2 changes: 1 addition & 1 deletion systemd/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os as _os
from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)
from ._journal import sendv, stream_fd
from ._journal import sendv, stream_fd, journal_print

def _make_line(field, value):
if isinstance(value, bytes):
Expand Down