summaryrefslogtreecommitdiff
path: root/efl/utils
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2013-10-28 16:54:23 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2013-10-28 18:55:58 +0200
commit6a0e8a716669e65e7ce910ee5a18f3a1eaf202d8 (patch)
tree246c1b5dc1b851e62039d527d946e8b7d9faa6dc /efl/utils
parent1e40a8f5bbe493801143b0e2647e958c5d3a11ec (diff)
Fix customization of logger class when using Py2
Diffstat (limited to 'efl/utils')
-rw-r--r--efl/utils/logger.pyx21
1 files changed, 13 insertions, 8 deletions
diff --git a/efl/utils/logger.pyx b/efl/utils/logger.pyx
index 515c566..2866a51 100644
--- a/efl/utils/logger.pyx
+++ b/efl/utils/logger.pyx
@@ -54,19 +54,24 @@ cdef void py_eina_log_print_cb(const_Eina_Log_Domain *d,
54 54
55eina_log_print_cb_set(py_eina_log_print_cb, NULL) 55eina_log_print_cb_set(py_eina_log_print_cb, NULL)
56 56
57def setLevel(self, lvl):
58 cname = self.name
59 if isinstance(cname, unicode): cname = PyUnicode_AsUTF8String(cname)
60 eina_log_domain_level_set(cname, log_levels.index(lvl))
61 logging.Logger.setLevel(self, lvl)
62
57class PyEFLLogger(logging.Logger): 63class PyEFLLogger(logging.Logger):
64
58 def __init__(self, name): 65 def __init__(self, name):
59 cname = name 66 cname = name
60 if isinstance(cname, unicode): cname = PyUnicode_AsUTF8String(cname) 67 if isinstance(cname, unicode): cname = PyUnicode_AsUTF8String(cname)
61 self.eina_log_domain = eina_log_domain_register(cname, NULL) 68 self.eina_log_domain = eina_log_domain_register(cname, NULL)
62 loggers[name] = self 69 loggers[name] = self
63 logging.Logger.__init__(self, name) 70 logging.Logger.__init__(self, name)
64 71 if PY_VERSION_HEX < 0x03000000:
65 def setLevel(self, lvl): 72 self.setLevel = types.MethodType(setLevel, self, type(self))
66 cname = self.name 73 else:
67 if isinstance(cname, unicode): cname = PyUnicode_AsUTF8String(cname) 74 self.setLevel = types.MethodType(setLevel, self)
68 eina_log_domain_level_set(cname, log_levels.index(lvl))
69 logging.Logger.setLevel(self, lvl)
70 75
71cdef object add_logger(object name): 76cdef object add_logger(object name):
72 logging.setLoggerClass(PyEFLLogger) 77 logging.setLoggerClass(PyEFLLogger)
@@ -82,9 +87,9 @@ cdef object add_logger(object name):
82 lvl = log.getEffectiveLevel() 87 lvl = log.getEffectiveLevel()
83 eina_log_domain_level_set(cname, log_levels.index(lvl)) 88 eina_log_domain_level_set(cname, log_levels.index(lvl))
84 if PY_VERSION_HEX < 0x03000000: 89 if PY_VERSION_HEX < 0x03000000:
85 log.setLevel = types.MethodType(PyEFLLogger.setLevel, log, PyEFLLogger) 90 log.setLevel = types.MethodType(setLevel, log, type(log))
86 else: 91 else:
87 log.setLevel = types.MethodType(PyEFLLogger.setLevel, log) 92 log.setLevel = types.MethodType(setLevel, log)
88 else: 93 else:
89 log.propagate = True 94 log.propagate = True
90 log.setLevel(logging.WARNING) 95 log.setLevel(logging.WARNING)