Commit 50bcafea authored by Devaev Maxim's avatar Devaev Maxim

Fixed bug with logging, added tracer for dbus API

parent e4a3f944
[service] [service]
bus_type = session bus_type = session
log_level = 2
[hello] [hello]
enabled = yes enabled = yes
...@@ -15,7 +15,7 @@ ConfigDictObject = { ...@@ -15,7 +15,7 @@ ConfigDictObject = {
"name" : (const.DEFAULT_SERVICE_NAME, str), "name" : (const.DEFAULT_SERVICE_NAME, str),
"path" : (const.DEFAULT_SERVICE_PATH, str), "path" : (const.DEFAULT_SERVICE_PATH, str),
"bus_type" : (const.DEFAULT_SERVICE_BUS_TYPE, ( lambda arg : validators.validRange(arg, const.ALL_SERVICE_BUS_TYPES_LIST) )), "bus_type" : (const.DEFAULT_SERVICE_BUS_TYPE, ( lambda arg : validators.validRange(arg, const.ALL_SERVICE_BUS_TYPES_LIST) )),
"log_level" : (const.DEFAULT_LOG_LEVEL, ( lambda arg : int(validators.validRange(arg, const.ALL_LOG_LEVELS_LIST)) )) "log_level" : (const.DEFAULT_LOG_LEVEL, ( lambda arg : validators.validRange(int(arg), const.ALL_LOG_LEVELS_LIST) ))
} }
} }
...@@ -34,7 +34,7 @@ def setValue(section, option, value, validator = None) : ...@@ -34,7 +34,7 @@ def setValue(section, option, value, validator = None) :
try : try :
value = validator(value) value = validator(value)
except Exception, err1 : except Exception, err1 :
raise validators.ValidatorError("Incorrect config option \"%s :: %s = %s\"" % (section, option, value, str(err1))) raise validators.ValidatorError("Incorrect config option \"%s :: %s = %s\": %s" % (section, option, value, str(err1)))
ConfigDictObject[section][option] = (value, validator) ConfigDictObject[section][option] = (value, validator)
......
...@@ -14,6 +14,7 @@ def message(log_level, message) : ...@@ -14,6 +14,7 @@ def message(log_level, message) :
"%s [ Details ]:" % (const.MY_NAME), # const.LOG_LEVEL_VERBOSE == 1 "%s [ Details ]:" % (const.MY_NAME), # const.LOG_LEVEL_VERBOSE == 1
"%s [ Debug ]:" % (const.MY_NAME) # # const.LOG_LEVEL_DEBUG == 2 "%s [ Debug ]:" % (const.MY_NAME) # # const.LOG_LEVEL_DEBUG == 2
] ]
if log_level <= config.value("service", "log_level") : if log_level <= config.value("service", "log_level") :
print >> sys.stderr, text_log_levels_list[log_level], message print >> sys.stderr, text_log_levels_list[log_level], message
...@@ -5,9 +5,11 @@ import dbus.service ...@@ -5,9 +5,11 @@ import dbus.service
import dbus.glib import dbus.glib
import abc import abc
import const
import config import config
import shared import shared
import dbus_tools import dbus_tools
import logger
##### #####
...@@ -57,9 +59,21 @@ class ActionObject(CustomObject) : ...@@ -57,9 +59,21 @@ class ActionObject(CustomObject) :
###### ######
def tracer(function) :
def wrapper(self, *args_list, **kwargs_dict) :
return_value = function(self, *args_list, **kwargs_dict)
logger.message(const.LOG_LEVEL_DEBUG, "Called \"%s::%s\" with args (%s, %s) --> %s" % (
self.__class__.__name__, function.__name__, str(args_list), str(kwargs_dict), str(return_value) ))
return return_value
wrapper.__dict__ = function.__dict__
wrapper.__name__ = function.__name__
return wrapper
def customMethod(interface_name) : def customMethod(interface_name) :
def decorator(function) : def decorator(function) :
return dbus.service.method(interface_name)(function) return tracer(dbus.service.method(interface_name)(function))
return decorator return decorator
def functionMethod(interface_name) : def functionMethod(interface_name) :
......
...@@ -20,6 +20,5 @@ def validBool(arg) : ...@@ -20,6 +20,5 @@ def validBool(arg) :
def validRange(arg, valid_args_list) : def validRange(arg, valid_args_list) :
if not arg in valid_args_list : if not arg in valid_args_list :
raise ValidatorError("Argument \"%s\" not in list %s" % (arg, valid_args_list)) raise ValidatorError("Argument \"%s\" not in list %s" % (arg, valid_args_list))
return arg
return ( arg in valid_args_list )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment