Skip to content
This repository
tree: ba2c01464e
Fetching contributors…

Cannot retrieve contributors at this time

file 64 lines (61 sloc) 1.61 kb
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
/*-------------------------------------------------------------------------
*
* The Multicorn Foreign Data Wrapper allows you to fetch foreign data in
* Python in your PostgreSQL
*
* This software is released under the postgresql licence
*
* author: Kozea
*
*
*-------------------------------------------------------------------------
*/
#include <Python.h>
#include "postgres.h"

static PyObject* log_to_postgres(PyObject* self, PyObject *args, PyObject* kwargs)
{
    const char* message;
    const int level = 1;
    int severity;
    PyObject* hint;
    if(!PyArg_ParseTuple(args, "s|i", &message, &level)){
        return ;
    }
    switch(level)
    {
        case 0:
            severity = DEBUG1;
            break;
        case 1:
            severity = NOTICE;
            break;
        case 2:
            severity = WARNING;
            break;
        case 3:
            severity = ERROR;
            break;
        case 4:
            severity = FATAL;
            break;
        default:
            severity = INFO;
            break;
    }
    hint = PyDict_GetItemString(kwargs, "hint");
    if(hint != NULL && hint != Py_None){
        ereport(severity, (errmsg("%s", message), errhint("%s", PyString_AsString(hint))));
    } else {
        ereport(severity, (errmsg("%s", message)));
    }
    return Py_None;
}

static PyMethodDef UtilsMethods[] = {
    {"_log_to_postgres", log_to_postgres, METH_VARARGS | METH_KEYWORDS, "Log to postresql client"},
    {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
init_utils(void)
{
    (void) Py_InitModule("multicorn._utils", UtilsMethods);
}
Something went wrong with that request. Please try again.