1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/*
* Copyright (c) 2019 Balabit
* Copyright (c) 2019 Kokan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#include "python-logger.h"
#include "python-helpers.h"
#include "messages.h"
PyTypeObject py_logger_type;
PyObject *
py_msg_error(PyObject *obj, PyObject *args)
{
char *message = NULL;
if (!PyArg_ParseTuple(args, "s", &message))
return NULL;
msg_error(message);
Py_RETURN_NONE;
}
PyObject *
py_msg_warning(PyObject *obj, PyObject *args)
{
char *message = NULL;
if (!PyArg_ParseTuple(args, "s", &message))
return NULL;
msg_warning(message);
Py_RETURN_NONE;
}
PyObject *
py_msg_info(PyObject *obj, PyObject *args)
{
char *message = NULL;
if (!PyArg_ParseTuple(args, "s", &message))
return NULL;
msg_info(message);
Py_RETURN_NONE;
}
PyObject *
py_msg_debug(PyObject *obj, PyObject *args)
{
if (!debug_flag)
Py_RETURN_NONE;
char *message = NULL;
if (!PyArg_ParseTuple(args, "s", &message))
return NULL;
msg_debug(message);
Py_RETURN_NONE;
}
PyObject *
py_msg_trace(PyObject *obj, PyObject *args)
{
if (!trace_flag)
Py_RETURN_NONE;
char *message = NULL;
if (!PyArg_ParseTuple(args, "s", &message))
return NULL;
msg_trace(message);
Py_RETURN_NONE;
}
static PyMethodDef py_logger_methods[] =
{
{ "error", (PyCFunction)py_msg_error, METH_VARARGS, "msg_error" },
{ "warning", (PyCFunction)py_msg_warning, METH_VARARGS, "msg_warning" },
{ "info", (PyCFunction)py_msg_info, METH_VARARGS, "msg_info" },
{ "debug", (PyCFunction)py_msg_debug, METH_VARARGS, "msg_debug" },
{ "trace", (PyCFunction)py_msg_trace, METH_VARARGS, "msg_trace" },
{ NULL }
};
PyTypeObject py_logger_type =
{
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_basicsize = sizeof(PyObject),
.tp_dealloc = py_slng_generic_dealloc,
.tp_doc = "Those messages can be captured by internal() source.",
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_methods = py_logger_methods,
.tp_name = "Logger",
.tp_new = PyType_GenericNew,
0
};
void
py_logger_global_init(void)
{
PyType_Ready(&py_logger_type);
PyModule_AddObject(PyImport_AddModule("_syslogng"), "Logger", (PyObject *) &py_logger_type);
}
|