Move logger to its own module.
This commit is contained in:
parent
8cbee5c44d
commit
4771ca5ccb
|
@ -0,0 +1 @@
|
|||
import efl.utils.logger
|
|
@ -15,80 +15,22 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
cimport cython
|
||||
from cpython cimport PyObject, Py_INCREF, Py_DECREF, PyUnicode_AsUTF8String, \
|
||||
PyString_FromFormatV
|
||||
from cpython cimport PyObject, Py_INCREF, Py_DECREF, PyUnicode_AsUTF8String
|
||||
from libc.stdlib cimport malloc, free
|
||||
from libc.string cimport memcpy, strdup
|
||||
from efl.eina cimport Eina_Bool, const_Eina_List, eina_list_append, const_void, \
|
||||
Eina_Hash, eina_hash_string_superfast_new, eina_hash_add, eina_hash_del, \
|
||||
eina_hash_find, Eina_Log_Domain, const_Eina_Log_Domain, Eina_Log_Level, \
|
||||
eina_log_print_cb_set, eina_log_domain_register, \
|
||||
eina_log_level_set, eina_log_level_get, eina_log_domain_level_get, \
|
||||
eina_log_domain_level_set, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO
|
||||
eina_hash_find, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO
|
||||
from efl.c_eo cimport Eo as cEo, eo_init, eo_shutdown, eo_del, eo_do, \
|
||||
eo_class_name_get, eo_class_get, eo_base_data_set, eo_base_data_get, \
|
||||
eo_base_data_del, eo_event_callback_add, eo_event_callback_del, \
|
||||
Eo_Event_Description, const_Eo_Event_Description, \
|
||||
eo_parent_get, EO_EV_DEL
|
||||
|
||||
from efl.utils.logger cimport add_logger
|
||||
|
||||
cdef extern from "stdarg.h":
|
||||
ctypedef struct va_list:
|
||||
pass
|
||||
|
||||
cdef void py_eina_log_print_cb(const_Eina_Log_Domain *d,
|
||||
Eina_Log_Level level,
|
||||
const_char *file, const_char *fnc, int line,
|
||||
const_char *fmt, void *data, va_list args) with gil:
|
||||
cdef str msg = PyString_FromFormatV(fmt, args)
|
||||
rec = logging.LogRecord(d.name, log_levels[level], file, line, msg, None, None, fnc)
|
||||
logger = loggers.get(d.name, loggers["efl"])
|
||||
logger.handle(rec)
|
||||
|
||||
eina_log_print_cb_set(py_eina_log_print_cb, NULL)
|
||||
|
||||
|
||||
import logging
|
||||
|
||||
cdef tuple log_levels = (
|
||||
50,
|
||||
40,
|
||||
30,
|
||||
20,
|
||||
10
|
||||
)
|
||||
|
||||
cdef dict loggers = dict()
|
||||
|
||||
class PyEFLLogger(logging.Logger):
|
||||
def __init__(self, name):
|
||||
self.eina_log_domain = eina_log_domain_register(name, NULL)
|
||||
loggers[name] = self
|
||||
logging.Logger.__init__(self, name)
|
||||
|
||||
def setLevel(self, lvl):
|
||||
eina_log_domain_level_set(self.name, log_levels.index(lvl))
|
||||
logging.Logger.setLevel(self, lvl)
|
||||
|
||||
logging.setLoggerClass(PyEFLLogger)
|
||||
|
||||
# TODO: Handle messages from root Eina Log with this one?
|
||||
rootlog = logging.getLogger("efl")
|
||||
rootlog.propagate = False
|
||||
rootlog.setLevel(logging.WARNING)
|
||||
rootlog.addHandler(logging.NullHandler())
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
log.propagate = True
|
||||
log.setLevel(logging.WARNING)
|
||||
log.addHandler(logging.NullHandler())
|
||||
|
||||
logging.setLoggerClass(logging.Logger)
|
||||
|
||||
cdef int PY_EFL_EO_LOG_DOMAIN = log.eina_log_domain
|
||||
|
||||
|
||||
# Set this to public and export it in pxd if you need it in another module
|
||||
cdef int PY_EFL_EO_LOG_DOMAIN = add_logger(__name__)
|
||||
|
||||
|
||||
def init():
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
# Copyright (C) 2007-2013 various contributors (see AUTHORS)
|
||||
#
|
||||
# This file is part of Python-EFL.
|
||||
#
|
||||
# Python-EFL is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# Python-EFL is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from cpython cimport PyString_FromFormatV
|
||||
from libc.string cimport const_char
|
||||
from efl.eina cimport Eina_Log_Domain, const_Eina_Log_Domain, Eina_Log_Level, \
|
||||
eina_log_print_cb_set, eina_log_domain_register, eina_log_level_set, \
|
||||
eina_log_level_get, eina_log_domain_level_get, eina_log_domain_level_set
|
||||
|
||||
cdef extern from "stdarg.h":
|
||||
ctypedef struct va_list:
|
||||
pass
|
||||
|
||||
cdef tuple log_levels = (
|
||||
50,
|
||||
40,
|
||||
30,
|
||||
20,
|
||||
10
|
||||
)
|
||||
|
||||
cdef dict loggers = dict()
|
||||
|
||||
cdef void py_eina_log_print_cb(const_Eina_Log_Domain *d,
|
||||
Eina_Log_Level level,
|
||||
const_char *file, const_char *fnc, int line,
|
||||
const_char *fmt, void *data, va_list args) with gil:
|
||||
cdef str msg = PyString_FromFormatV(fmt, args)
|
||||
rec = logging.LogRecord(d.name, log_levels[level], file, line, msg, None, None, fnc)
|
||||
logger = loggers.get(d.name, loggers["efl"])
|
||||
logger.handle(rec)
|
||||
|
||||
import logging
|
||||
|
||||
eina_log_print_cb_set(py_eina_log_print_cb, NULL)
|
||||
|
||||
class PyEFLLogger(logging.Logger):
|
||||
def __init__(self, name):
|
||||
self.eina_log_domain = eina_log_domain_register(name, NULL)
|
||||
loggers[name] = self
|
||||
logging.Logger.__init__(self, name)
|
||||
|
||||
def setLevel(self, lvl):
|
||||
eina_log_domain_level_set(self.name, log_levels.index(lvl))
|
||||
logging.Logger.setLevel(self, lvl)
|
||||
|
||||
logging.setLoggerClass(PyEFLLogger)
|
||||
|
||||
rootlog = logging.getLogger("efl")
|
||||
rootlog.propagate = False
|
||||
rootlog.setLevel(logging.WARNING)
|
||||
rootlog.addHandler(logging.NullHandler())
|
||||
|
||||
logging.setLoggerClass(logging.Logger)
|
||||
|
||||
cdef public int PY_EFL_LOG_DOMAIN = rootlog.eina_log_domain
|
||||
|
||||
cdef int add_logger(char *name):
|
||||
logging.setLoggerClass(PyEFLLogger)
|
||||
|
||||
log = logging.getLogger(name)
|
||||
log.propagate = True
|
||||
log.setLevel(logging.WARNING)
|
||||
log.addHandler(logging.NullHandler())
|
||||
|
||||
logging.setLoggerClass(logging.Logger)
|
||||
|
||||
return log.eina_log_domain
|
|
@ -21,20 +21,22 @@ from efl.c_eo cimport Eo as cEo
|
|||
|
||||
from efl.eina cimport Eina_List, const_Eina_List
|
||||
|
||||
cdef class Eo(object):
|
||||
cdef cEo *obj
|
||||
cdef readonly dict data
|
||||
cdef:
|
||||
class Eo(object):
|
||||
cdef:
|
||||
cEo *obj
|
||||
readonly dict data
|
||||
|
||||
cdef void _set_obj(self, cEo *obj) except *
|
||||
cdef void _set_properties_from_keyword_args(self, dict kwargs) except *
|
||||
# cdef void *_unset_obj(self)
|
||||
# cdef _add_obj(self, Eo_Class *klass, cEo *parent)
|
||||
void _set_obj(self, cEo *obj) except *
|
||||
void _set_properties_from_keyword_args(self, dict kwargs) except *
|
||||
#void *_unset_obj(self)
|
||||
#_add_obj(self, Eo_Class *klass, cEo *parent)
|
||||
|
||||
|
||||
cdef int PY_REFCOUNT(object o)
|
||||
int PY_REFCOUNT(object o)
|
||||
|
||||
cdef object object_from_instance(cEo *obj)
|
||||
cdef void _object_mapping_register(char *name, object cls) except *
|
||||
cdef void _object_mapping_unregister(char *name)
|
||||
object object_from_instance(cEo *obj)
|
||||
void _object_mapping_register(char *name, object cls) except *
|
||||
void _object_mapping_unregister(char *name)
|
||||
|
||||
cdef void _register_decorated_callbacks(object obj)
|
||||
void _register_decorated_callbacks(object obj)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
cdef:
|
||||
int add_logger(char *name)
|
||||
int PY_EFL_LOG_DOMAIN
|
11
setup.py
11
setup.py
|
@ -86,11 +86,18 @@ if set(("build", "build_ext", "install", "bdist", "sdist")) & set(sys.argv):
|
|||
|
||||
# Utilities
|
||||
utils_ext = [
|
||||
Extension("utils.deprecated", ["efl/utils/deprecated"+module_suffix]),
|
||||
Extension("utils.deprecated", ["efl/utils/deprecated"+module_suffix],
|
||||
include_dirs = ['include/'],
|
||||
extra_compile_args = eo_cflags,
|
||||
extra_link_args = eo_libs + eina_libs),
|
||||
Extension("utils.conversions", ["efl/utils/conversions"+module_suffix],
|
||||
include_dirs = ['include/'],
|
||||
extra_compile_args = eo_cflags,
|
||||
extra_link_args = eo_libs + eina_libs)
|
||||
extra_link_args = eo_libs + eina_libs),
|
||||
Extension("utils.logger", ["efl/utils/logger"+module_suffix],
|
||||
include_dirs = ['include/'],
|
||||
extra_compile_args = eo_cflags,
|
||||
extra_link_args = eo_libs + eina_libs),
|
||||
]
|
||||
modules += utils_ext
|
||||
|
||||
|
|
Loading…
Reference in New Issue