Skip to content
Snippets Groups Projects
Commit b7453f87 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

The wrapping of the log_it function has been added, a test has also been added...

The wrapping of the log_it function has been added, a test has also been added for the fact that it works
parent 7de4fa44
No related branches found
No related tags found
No related merge requests found
...@@ -53,31 +53,70 @@ static PyObject *dap_set_log_level(PyObject *self, PyObject *args){ ...@@ -53,31 +53,70 @@ static PyObject *dap_set_log_level(PyObject *self, PyObject *args){
const char *data; const char *data;
if (!PyArg_ParseTuple(args, "s", &data)) if (!PyArg_ParseTuple(args, "s", &data))
return NULL; return NULL;
if (strcmp(data,"DEBUG") == 0){ dap_log_level_t new_log_level = convert_const_char_to_dap_log_level(data);
dap_log_level_set(L_DEBUG); if (new_log_level == -1) {
return PyLong_FromLong(-1);
} else {
dap_log_level_set(new_log_level);
return PyLong_FromLong(0); return PyLong_FromLong(0);
} }
if (strcmp(data, "INFO") == 0){ }
dap_log_level_set(L_INFO);
return PyLong_FromLong(0); static dap_log_level_t convert_const_char_to_dap_log_level(const char* string){
if (strcmp(string,"DEBUG") == 0){
return L_DEBUG;
} }
if (strcmp(data, "NOTICE") == 0){ if (strcmp(string, "INFO") == 0){
dap_log_level_set(L_NOTICE); return L_INFO;
return PyLong_FromLong(0);
} }
if (strcmp(data, "WARNING") == 0){ if (strcmp(string, "NOTICE") == 0){
dap_log_level_set(L_WARNING); return L_NOTICE;
return PyLong_FromLong(0);
} }
if (strcmp(data, "ERROR") == 0){ if (strcmp(string, "WARNING") == 0){
dap_log_level_set(L_ERROR); return L_WARNING;
return PyLong_FromLong(0);
} }
if (strcmp(data, "CRITICAL") == 0){ if (strcmp(string, "ERROR") == 0){
dap_log_level_set(L_CRITICAL); return L_ERROR;
return PyLong_FromLong(0);
} }
return PyLong_FromLong(-1); if (strcmp(string, "CRITICAL") == 0){
return L_CRITICAL;
}
return -1;
}
static PyObject* dap_log_it(PyObject* self, PyObject* args){
const char *data;
if (!PyArg_ParseTuple(args, "s", &data))
return NULL;
char* dap_log_leve_char;
char* string_output;
int len_log_level_char=0;
int len_string_output=0;
int countSeparators=0;
int lenMassives = 0;
while (*(data+lenMassives) != '\0'){
if (*(data+lenMassives)=='\n'){
countSeparators += 1;
}else {
if (countSeparators == 0)
len_log_level_char++;
if (countSeparators == 1)
len_string_output++;
}
lenMassives++;
}
if (len_log_level_char == 0 || len_string_output == 0)
return PyLong_FromLong(-1);
dap_log_leve_char = calloc(len_log_level_char, sizeof(char));
string_output = calloc(len_string_output, sizeof(char));
memcpy(dap_log_leve_char, data, len_log_level_char);
memcpy(string_output, data+len_log_level_char+1, len_string_output);
dap_log_level_t log_level = convert_const_char_to_dap_log_level(dap_log_leve_char);
if (log_level == -1)
return PyLong_FromLong(-1);
log_it(log_level, string_output);
return PyLong_FromLong(0);
} }
PyMODINIT_FUNC PyInit_libdap_python_module(void){ PyMODINIT_FUNC PyInit_libdap_python_module(void){
......
...@@ -15,10 +15,15 @@ static PyObject *dap_deinit(PyObject *self); ...@@ -15,10 +15,15 @@ static PyObject *dap_deinit(PyObject *self);
static PyObject *dap_set_log_level(PyObject *self, PyObject *args); static PyObject *dap_set_log_level(PyObject *self, PyObject *args);
static PyObject* dap_log_it(PyObject* self, PyObject* args);
static dap_log_level_t convert_const_char_to_dap_log_level(const char* string);
static PyMethodDef DapMethods[] = { static PyMethodDef DapMethods[] = {
{"init", dap_init, METH_VARARGS, "Initialization of the DAP (Deus Applicaions Prototypes) library"}, {"init", dap_init, METH_VARARGS, "Initialization of the DAP (Deus Applicaions Prototypes) library"},
{"deinit", dap_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) library"}, {"deinit", dap_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) library"},
{"setLogLevel", dap_set_log_level, METH_VARARGS, "Setting the logging level"}, {"setLogLevel", dap_set_log_level, METH_VARARGS, "Setting the logging level"},
{"logIt", dap_log_it, METH_VARARGS, "The wrapper of the log_it function for the libdap library"},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
......
...@@ -20,5 +20,11 @@ class Dap: ...@@ -20,5 +20,11 @@ class Dap:
self.log_level=data self.log_level=data
res_setLogLevel = libdap_python_module.setLogLevel(data) res_setLogLevel = libdap_python_module.setLogLevel(data)
if res_setLogLevel == -1: if res_setLogLevel == -1:
raise DapIniException("Failed to set the logging level, perhaps you did correctly specify the name of the level") raise DapIniException("Failed to set the logging level, perhaps you did not correctly specify the name of the level")
def logIt(self, data):
parse_data = json.loads(data)
res_log_it = libdap_python_module.logIt(parse_data['level']+"\n"+parse_data['data'])
if res_log_it == -1:
raise DapIniException("Could not execute log_it function. Perhaps you did not correctly specify the name of the logging level or did not leave the information that needs to be displayed")
...@@ -13,3 +13,8 @@ daptest = libdapConnector.Dap(json_string) ...@@ -13,3 +13,8 @@ daptest = libdapConnector.Dap(json_string)
print("Initialization of the DAP") print("Initialization of the DAP")
daptest.setLogLevel("DEBUG") daptest.setLogLevel("DEBUG")
print("Level logging ""DEBUG"" done") print("Level logging ""DEBUG"" done")
daptest.logIt("""{
"level": "DEBUG",
"data": "Test. Outputting a string using the log_it function in the libdap library"
}""")
print("Outputting a string using the log_it function done")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment