summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2013-10-24 22:58:09 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2013-10-24 22:58:09 +0300
commit4771ca5ccb7654119a67de72dc28020e091bc3b5 (patch)
tree7c15896f60b241802fc1fffb7e6c1e00baa680e9
parent8cbee5c44d706a9fc25bfc7f841d25745fadb40b (diff)
Move logger to its own module.
-rw-r--r--efl/__init__.py1
-rw-r--r--efl/eo/efl.eo.pyx68
-rw-r--r--efl/utils/logger.pyx82
-rw-r--r--include/efl.eo.pxd26
-rw-r--r--include/efl.utils.logger.pxd3
-rwxr-xr-xsetup.py11
6 files changed, 114 insertions, 77 deletions
diff --git a/efl/__init__.py b/efl/__init__.py
index e69de29..5fc98c8 100644
--- a/efl/__init__.py
+++ b/efl/__init__.py
@@ -0,0 +1 @@
import efl.utils.logger
diff --git a/efl/eo/efl.eo.pyx b/efl/eo/efl.eo.pyx
index c54739b..8e9bbd1 100644
--- a/efl/eo/efl.eo.pyx
+++ b/efl/eo/efl.eo.pyx
@@ -15,80 +15,22 @@
15# You should have received a copy of the GNU Lesser General Public License 15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>. 16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17 17
18cimport cython 18from cpython cimport PyObject, Py_INCREF, Py_DECREF, PyUnicode_AsUTF8String
19from cpython cimport PyObject, Py_INCREF, Py_DECREF, PyUnicode_AsUTF8String, \
20 PyString_FromFormatV
21from libc.stdlib cimport malloc, free 19from libc.stdlib cimport malloc, free
22from libc.string cimport memcpy, strdup 20from libc.string cimport memcpy, strdup
23from efl.eina cimport Eina_Bool, const_Eina_List, eina_list_append, const_void, \ 21from efl.eina cimport Eina_Bool, const_Eina_List, eina_list_append, const_void, \
24 Eina_Hash, eina_hash_string_superfast_new, eina_hash_add, eina_hash_del, \ 22 Eina_Hash, eina_hash_string_superfast_new, eina_hash_add, eina_hash_del, \
25 eina_hash_find, Eina_Log_Domain, const_Eina_Log_Domain, Eina_Log_Level, \ 23 eina_hash_find, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO
26 eina_log_print_cb_set, eina_log_domain_register, \
27 eina_log_level_set, eina_log_level_get, eina_log_domain_level_get, \
28 eina_log_domain_level_set, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO
29from efl.c_eo cimport Eo as cEo, eo_init, eo_shutdown, eo_del, eo_do, \ 24from efl.c_eo cimport Eo as cEo, eo_init, eo_shutdown, eo_del, eo_do, \
30 eo_class_name_get, eo_class_get, eo_base_data_set, eo_base_data_get, \ 25 eo_class_name_get, eo_class_get, eo_base_data_set, eo_base_data_get, \
31 eo_base_data_del, eo_event_callback_add, eo_event_callback_del, \ 26 eo_base_data_del, eo_event_callback_add, eo_event_callback_del, \
32 Eo_Event_Description, const_Eo_Event_Description, \ 27 Eo_Event_Description, const_Eo_Event_Description, \
33 eo_parent_get, EO_EV_DEL 28 eo_parent_get, EO_EV_DEL
34 29
30from efl.utils.logger cimport add_logger
35 31
36cdef extern from "stdarg.h": 32# Set this to public and export it in pxd if you need it in another module
37 ctypedef struct va_list: 33cdef int PY_EFL_EO_LOG_DOMAIN = add_logger(__name__)
38 pass
39
40cdef void py_eina_log_print_cb(const_Eina_Log_Domain *d,
41 Eina_Log_Level level,
42 const_char *file, const_char *fnc, int line,
43 const_char *fmt, void *data, va_list args) with gil:
44 cdef str msg = PyString_FromFormatV(fmt, args)
45 rec = logging.LogRecord(d.name, log_levels[level], file, line, msg, None, None, fnc)
46 logger = loggers.get(d.name, loggers["efl"])
47 logger.handle(rec)
48
49eina_log_print_cb_set(py_eina_log_print_cb, NULL)
50
51
52import logging
53
54cdef tuple log_levels = (
55 50,
56 40,
57 30,
58 20,
59 10
60)
61
62cdef dict loggers = dict()
63
64class PyEFLLogger(logging.Logger):
65 def __init__(self, name):
66 self.eina_log_domain = eina_log_domain_register(name, NULL)
67 loggers[name] = self
68 logging.Logger.__init__(self, name)
69
70 def setLevel(self, lvl):
71 eina_log_domain_level_set(self.name, log_levels.index(lvl))
72 logging.Logger.setLevel(self, lvl)
73
74logging.setLoggerClass(PyEFLLogger)
75
76# TODO: Handle messages from root Eina Log with this one?
77rootlog = logging.getLogger("efl")
78rootlog.propagate = False
79rootlog.setLevel(logging.WARNING)
80rootlog.addHandler(logging.NullHandler())
81
82log = logging.getLogger(__name__)
83log.propagate = True
84log.setLevel(logging.WARNING)
85log.addHandler(logging.NullHandler())
86
87logging.setLoggerClass(logging.Logger)
88
89cdef int PY_EFL_EO_LOG_DOMAIN = log.eina_log_domain
90
91
92 34
93 35
94def init(): 36def init():
diff --git a/efl/utils/logger.pyx b/efl/utils/logger.pyx
new file mode 100644
index 0000000..471de9e
--- /dev/null
+++ b/efl/utils/logger.pyx
@@ -0,0 +1,82 @@
1# Copyright (C) 2007-2013 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18from cpython cimport PyString_FromFormatV
19from libc.string cimport const_char
20from efl.eina cimport Eina_Log_Domain, const_Eina_Log_Domain, Eina_Log_Level, \
21 eina_log_print_cb_set, eina_log_domain_register, eina_log_level_set, \
22 eina_log_level_get, eina_log_domain_level_get, eina_log_domain_level_set
23
24cdef extern from "stdarg.h":
25 ctypedef struct va_list:
26 pass
27
28cdef tuple log_levels = (
29 50,
30 40,
31 30,
32 20,
33 10
34)
35
36cdef dict loggers = dict()
37
38cdef void py_eina_log_print_cb(const_Eina_Log_Domain *d,
39 Eina_Log_Level level,
40 const_char *file, const_char *fnc, int line,
41 const_char *fmt, void *data, va_list args) with gil:
42 cdef str msg = PyString_FromFormatV(fmt, args)
43 rec = logging.LogRecord(d.name, log_levels[level], file, line, msg, None, None, fnc)
44 logger = loggers.get(d.name, loggers["efl"])
45 logger.handle(rec)
46
47import logging
48
49eina_log_print_cb_set(py_eina_log_print_cb, NULL)
50
51class PyEFLLogger(logging.Logger):
52 def __init__(self, name):
53 self.eina_log_domain = eina_log_domain_register(name, NULL)
54 loggers[name] = self
55 logging.Logger.__init__(self, name)
56
57 def setLevel(self, lvl):
58 eina_log_domain_level_set(self.name, log_levels.index(lvl))
59 logging.Logger.setLevel(self, lvl)
60
61logging.setLoggerClass(PyEFLLogger)
62
63rootlog = logging.getLogger("efl")
64rootlog.propagate = False
65rootlog.setLevel(logging.WARNING)
66rootlog.addHandler(logging.NullHandler())
67
68logging.setLoggerClass(logging.Logger)
69
70cdef public int PY_EFL_LOG_DOMAIN = rootlog.eina_log_domain
71
72cdef int add_logger(char *name):
73 logging.setLoggerClass(PyEFLLogger)
74
75 log = logging.getLogger(name)
76 log.propagate = True
77 log.setLevel(logging.WARNING)
78 log.addHandler(logging.NullHandler())
79
80 logging.setLoggerClass(logging.Logger)
81
82 return log.eina_log_domain
diff --git a/include/efl.eo.pxd b/include/efl.eo.pxd
index b46058f..ad3b7e5 100644
--- a/include/efl.eo.pxd
+++ b/include/efl.eo.pxd
@@ -21,20 +21,22 @@ from efl.c_eo cimport Eo as cEo
21 21
22from efl.eina cimport Eina_List, const_Eina_List 22from efl.eina cimport Eina_List, const_Eina_List
23 23
24cdef class Eo(object): 24cdef:
25 cdef cEo *obj 25 class Eo(object):
26 cdef readonly dict data 26 cdef:
27 cEo *obj
28 readonly dict data
27 29
28 cdef void _set_obj(self, cEo *obj) except * 30 void _set_obj(self, cEo *obj) except *
29 cdef void _set_properties_from_keyword_args(self, dict kwargs) except * 31 void _set_properties_from_keyword_args(self, dict kwargs) except *
30# cdef void *_unset_obj(self) 32 #void *_unset_obj(self)
31# cdef _add_obj(self, Eo_Class *klass, cEo *parent) 33 #_add_obj(self, Eo_Class *klass, cEo *parent)
32 34
33 35
34cdef int PY_REFCOUNT(object o) 36 int PY_REFCOUNT(object o)
35 37
36cdef object object_from_instance(cEo *obj) 38 object object_from_instance(cEo *obj)
37cdef void _object_mapping_register(char *name, object cls) except * 39 void _object_mapping_register(char *name, object cls) except *
38cdef void _object_mapping_unregister(char *name) 40 void _object_mapping_unregister(char *name)
39 41
40cdef void _register_decorated_callbacks(object obj) 42 void _register_decorated_callbacks(object obj)
diff --git a/include/efl.utils.logger.pxd b/include/efl.utils.logger.pxd
new file mode 100644
index 0000000..d09ce6d
--- /dev/null
+++ b/include/efl.utils.logger.pxd
@@ -0,0 +1,3 @@
1cdef:
2 int add_logger(char *name)
3 int PY_EFL_LOG_DOMAIN
diff --git a/setup.py b/setup.py
index fdc0700..e76faa0 100755
--- a/setup.py
+++ b/setup.py
@@ -86,11 +86,18 @@ if set(("build", "build_ext", "install", "bdist", "sdist")) & set(sys.argv):
86 86
87 # Utilities 87 # Utilities
88 utils_ext = [ 88 utils_ext = [
89 Extension("utils.deprecated", ["efl/utils/deprecated"+module_suffix]), 89 Extension("utils.deprecated", ["efl/utils/deprecated"+module_suffix],
90 include_dirs = ['include/'],
91 extra_compile_args = eo_cflags,
92 extra_link_args = eo_libs + eina_libs),
90 Extension("utils.conversions", ["efl/utils/conversions"+module_suffix], 93 Extension("utils.conversions", ["efl/utils/conversions"+module_suffix],
91 include_dirs = ['include/'], 94 include_dirs = ['include/'],
92 extra_compile_args = eo_cflags, 95 extra_compile_args = eo_cflags,
93 extra_link_args = eo_libs + eina_libs) 96 extra_link_args = eo_libs + eina_libs),
97 Extension("utils.logger", ["efl/utils/logger"+module_suffix],
98 include_dirs = ['include/'],
99 extra_compile_args = eo_cflags,
100 extra_link_args = eo_libs + eina_libs),
94 ] 101 ]
95 modules += utils_ext 102 modules += utils_ext
96 103