2013-12-13 19:44:17 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-12-31 22:46:06 +00:00
|
|
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
2013-12-13 19:44:17 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program 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 General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
2013-12-14 08:12:41 +00:00
|
|
|
Provide Error Handling and login Services
|
2013-12-13 19:44:17 +00:00
|
|
|
"""
|
|
|
|
import logging
|
2013-12-14 08:12:41 +00:00
|
|
|
import inspect
|
2013-12-13 19:44:17 +00:00
|
|
|
|
|
|
|
from openlp.core.common import trace_error_handler
|
2014-09-04 20:10:34 +00:00
|
|
|
|
2014-01-11 17:52:01 +00:00
|
|
|
DO_NOT_TRACE_EVENTS = ['timerEvent', 'paintEvent', 'drag_enter_event', 'drop_event', 'on_controller_size_changed',
|
|
|
|
'preview_size_changed', 'resizeEvent']
|
2013-12-13 19:44:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OpenLPMixin(object):
|
|
|
|
"""
|
|
|
|
Base Calling object for OpenLP classes.
|
|
|
|
"""
|
2014-09-04 20:10:34 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(OpenLPMixin, self).__init__(*args, **kwargs)
|
2013-12-19 20:17:06 +00:00
|
|
|
self.logger = logging.getLogger("%s.%s" % (self.__module__, self.__class__.__name__))
|
2013-12-23 07:03:56 +00:00
|
|
|
if self.logger.getEffectiveLevel() == logging.DEBUG:
|
|
|
|
for name, m in inspect.getmembers(self, inspect.ismethod):
|
|
|
|
if name not in DO_NOT_TRACE_EVENTS:
|
|
|
|
if not name.startswith("_") and not name.startswith("log"):
|
|
|
|
setattr(self, name, self.logging_wrapper(m, self))
|
2013-12-14 08:12:41 +00:00
|
|
|
|
|
|
|
def logging_wrapper(self, func, parent):
|
|
|
|
"""
|
|
|
|
Code to added debug wrapper to work on called functions within a decorated class.
|
|
|
|
"""
|
|
|
|
def wrapped(*args, **kwargs):
|
2016-05-14 04:24:46 +00:00
|
|
|
parent.logger.debug("Entering {function}".format(function=func.__name__))
|
2013-12-14 08:12:41 +00:00
|
|
|
try:
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
except Exception as e:
|
|
|
|
if parent.logger.getEffectiveLevel() <= logging.ERROR:
|
2016-05-14 04:24:46 +00:00
|
|
|
parent.logger.error('Exception in {function} : {error}'.format(function=func.__name__,
|
|
|
|
error=e))
|
2013-12-14 08:12:41 +00:00
|
|
|
raise e
|
|
|
|
return wrapped
|
|
|
|
|
|
|
|
def log_debug(self, message):
|
|
|
|
"""
|
2013-12-30 19:50:34 +00:00
|
|
|
Common log debug handler
|
2013-12-14 08:12:41 +00:00
|
|
|
"""
|
|
|
|
self.logger.debug(message)
|
|
|
|
|
|
|
|
def log_info(self, message):
|
|
|
|
"""
|
2013-12-30 19:50:34 +00:00
|
|
|
Common log info handler
|
2013-12-14 08:12:41 +00:00
|
|
|
"""
|
|
|
|
self.logger.info(message)
|
2013-12-13 19:44:17 +00:00
|
|
|
|
2016-09-04 16:15:57 +00:00
|
|
|
def log_warning(self, message):
|
|
|
|
"""
|
|
|
|
Common log warning handler
|
|
|
|
"""
|
|
|
|
self.logger.warning(message)
|
|
|
|
|
2013-12-13 19:44:17 +00:00
|
|
|
def log_error(self, message):
|
|
|
|
"""
|
|
|
|
Common log error handler which prints the calling path
|
|
|
|
"""
|
2013-12-14 08:12:41 +00:00
|
|
|
trace_error_handler(self.logger)
|
|
|
|
self.logger.error(message)
|
2013-12-13 19:44:17 +00:00
|
|
|
|
|
|
|
def log_exception(self, message):
|
|
|
|
"""
|
|
|
|
Common log exception handler which prints the calling path
|
|
|
|
"""
|
2013-12-14 08:12:41 +00:00
|
|
|
trace_error_handler(self.logger)
|
2014-03-20 19:10:31 +00:00
|
|
|
self.logger.exception(message)
|