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

Corrected. Now the log_it function accepts not JSON as input, but two...

Corrected. Now the log_it function accepts not JSON as input, but two parameters — the level of logging and the displayed string.
Corrected. The setLogLevel function does not accept a string with a level name, but a parameter from the LogLevel enumeration.
Accordingly, the LogLevel enumeration has been added, which contains logging levels from debug to critical.
parent c9a2d0a3
No related branches found
No related tags found
1 merge request!26Support 3689
......@@ -32,11 +32,10 @@ static PyObject *dap_deinit(){
}
static PyObject *dap_set_log_level(PyObject *self, PyObject *args){
const char *data;
if (!PyArg_ParseTuple(args, "s", &data))
short int new_log_level;
if (!PyArg_ParseTuple(args, "h", &new_log_level))
return NULL;
dap_log_level_t new_log_level = convert_const_char_to_dap_log_level(data);
if (new_log_level == -1) {
if (new_log_level < 0 || new_log_level > 5 ) {
return PyLong_FromLong(-1);
} else {
dap_log_level_set(new_log_level);
......@@ -67,16 +66,16 @@ static dap_log_level_t convert_const_char_to_dap_log_level(const char* string){
}
static PyObject* dap_log_it(PyObject* self, PyObject* args){
const char* dap_log_leve_char;
short int log_level;
const char* string_output;
if (!PyArg_ParseTuple(args, "s|s", &dap_log_leve_char, &string_output))
if (!PyArg_ParseTuple(args, "h|s", &log_level, &string_output))
return NULL;
dap_log_level_t log_level = convert_const_char_to_dap_log_level(dap_log_leve_char);
if (log_level == -1)
if (log_level < 0 || log_level > 5 ) {
return PyLong_FromLong(-1);
log_it(log_level, string_output);
return PyLong_FromLong(0);
} else {
dap_log_level_set(log_level);
return PyLong_FromLong(0);
}
}
static PyObject* py_m_dap_config_get_item(PyObject *self, PyObject *args){
......
import json
from enum import Enum
import libdap_python_module
class DapIniException(Exception):
pass
class LogLevel(Enum):
L_CRITICAL=5
L_ERROR=4
L_WARNING=3
L_NOTICE=2
L_INFO=1
L_DEBUG=0
def init(data):
res = json.loads(data)
modules=res['modules']
......@@ -13,18 +22,16 @@ def init(data):
res_init = libdap_python_module.init(config_dir, application_name)
if res_init == -1 or res_init == -2:
raise DapIniException("Initialization erorr")
if log_level != "NOTICE":
setLogLevel(log_level)
if log_level != LogLevel.L_NOTICE.name:
setLogLevel(LogLevel[log_level])
def deInit():
libdap_python_module.deinit()
def setLogLevel(data):
log_level=data
res_setLogLevel = libdap_python_module.setLogLevel(data)
def setLogLevel(logLevel):
res_setLogLevel = libdap_python_module.setLogLevel(logLevel.value)
if res_setLogLevel == -1:
raise DapIniException("Failed to set the logging level, perhaps you did not correctly specify the name of the level")
def logIt(data):
parse_data = json.loads(data)
res_log_it = libdap_python_module.logIt(parse_data['level'], parse_data['data'])
def logIt(logLevel, data):
res_log_it = libdap_python_module.logIt(logLevel.value, 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")
def configGetItem(section_path, item_name):
......
......@@ -4,19 +4,16 @@ json_string = """{
"modules": "libdap",
"dap": {
"config_dir": "/opt/dap/etc",
"log_level": "DEBUG",
"log_level": \""""+libdapConnector.LogLevel.L_DEBUG.name+"""\",
"application_name": "TestAPP"
}
}"""
print("Standard Configuration \n"+json_string)
libdapConnector.init(json_string)
print("Initialization of the DAP")
libdapConnector.setLogLevel("DEBUG")
libdapConnector.setLogLevel(libdapConnector.LogLevel.L_DEBUG)
print("Level logging ""DEBUG"" done")
libdapConnector.logIt("""{
"level": "DEBUG",
"data": "Test. Outputting a string using the log_it function in the libdap library"
}""")
libdapConnector.logIt(libdapConnector.LogLevel.L_DEBUG, "Test. Outputting a string using the log_it function in the libdap library")
print("Outputting a string using the log_it function done")
res1 = libdapConnector.configGetItem("server", "listen_address")
print("Output [server] 'listen_address' = "+res1+"\n")
......
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