Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added function journal_print to wrap sd_journal_print #8

Merged
merged 1 commit into from

2 participants

@glittershark

Added a function journal_print that wraps sd_journal_print. This
function is defined in journal.c and then just imported in its base
state to journal.py.
It takes two arguments: one, one of the LOG
* constants, and the second
being a string to log.

Griffin Smith Added function journal_print to wrap sd_journal_print
Added a function journal_print that wraps sd_journal_print. This
function is defined in _journal.c and then just imported in its base
state to journal.py.
It takes two arguments: one, one of the LOG_* constants, and the second
being a string to log.
e9ec49f
@davidstrauss davidstrauss merged commit 17da6d4 into davidstrauss:master
@davidstrauss
Owner

Whoops. Shouldn't have merged this. Please use the upstream python-systemd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 22, 2013
  1. Added function journal_print to wrap sd_journal_print

    Griffin Smith authored
    Added a function journal_print that wraps sd_journal_print. This
    function is defined in _journal.c and then just imported in its base
    state to journal.py.
    It takes two arguments: one, one of the LOG_* constants, and the second
    being a string to log.
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 3 deletions.
  1. +30 −2 systemd/_journal.c
  2. +1 −1  systemd/journal.py
View
32 systemd/_journal.c
@@ -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)."
@@ -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 */
};
View
2  systemd/journal.py
@@ -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):
Something went wrong with that request. Please try again.