summaryrefslogtreecommitdiff
path: root/efl
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 /efl
parent8cbee5c44d706a9fc25bfc7f841d25745fadb40b (diff)
Move logger to its own module.
Diffstat (limited to 'efl')
-rw-r--r--efl/__init__.py1
-rw-r--r--efl/eo/efl.eo.pyx68
-rw-r--r--efl/utils/logger.pyx82
3 files changed, 88 insertions, 63 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