openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #22139
[Merge] lp:~trb143/openlp/refactor into lp:openlp
Tim Bentley has proposed merging lp:~trb143/openlp/refactor into lp:openlp.
Requested reviews:
Raoul Snyman (raoul-snyman)
For more details, see:
https://code.launchpad.net/~trb143/openlp/refactor/+merge/192825
This is work in progress and not complete.
This is a start to add trace functionality and clean up logging.
Add guards to on,y build log string if needed.
Needs tests and these will be added once the principles are agreed.
--
https://code.launchpad.net/~trb143/openlp/refactor/+merge/192825
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/common/__init__.py'
--- openlp/core/common/__init__.py 2013-10-13 20:36:42 +0000
+++ openlp/core/common/__init__.py 2013-10-27 17:30:33 +0000
@@ -103,6 +103,7 @@
Wrap = 2
Next = 3
+from .logger import trace, log_info, log_error, log_debug
from .uistrings import UiStrings
from .settings import Settings
from .applocation import AppLocation
=== added file 'openlp/core/common/logger.py'
--- openlp/core/common/logger.py 1970-01-01 00:00:00 +0000
+++ openlp/core/common/logger.py 2013-10-27 17:30:33 +0000
@@ -0,0 +1,102 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# 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 #
+###############################################################################
+"""
+This class contains the core logger functions.
+"""
+
+import inspect
+import logging
+
+# Events to never be logged. Usually timer events which will flood the log!
+DO_NOT_TRACE_EVENTS = ['timerEvent', 'paintEvent']
+
+
+def log_wrapper(func):
+ """
+ Code to added debug wrapper to work on called functions within a decorated class.
+ """
+ def wrapped(*args, **kwargs):
+ log = logging.getLogger(args[0].__module__)
+ if log.getEffectiveLevel() == logging.DEBUG:
+ log.debug("Entering %s" % func.__name__)
+ try:
+ return func(*args, **kwargs)
+ except Exception as e:
+ if log.getEffectiveLevel() <= logging.ERROR:
+ log.error('Exception in %s : %s' % (func.__name__, e))
+ return wrapped
+
+
+def trace(cls):
+ """
+ Decorator to add log_wrapper to all methods in calls unless they are banned!
+ """
+ for name, m in inspect.getmembers(cls, inspect.isfunction):
+ if name not in DO_NOT_TRACE_EVENTS:
+ setattr(cls, name, log_wrapper(m))
+ return cls
+
+
+def log_debug(*args):
+ """
+ Log_debug function with auto guard code.
+ Called by log_debug(self, text1, text2 etc)
+
+ `args`
+ Values to be used. Expects self to be the first parameter
+ """
+ log = logging.getLogger(args[0].__module__)
+ if log.getEffectiveLevel() == logging.DEBUG:
+ log.debug(''.join(text for text in args[1:]))
+
+
+def log_info(*args):
+ """
+ Log_info function with auto guard code.
+ Called by log_info(self, text1, text2 etc)
+
+ `args`
+ Values to be used. Expects self to be the first parameter
+ """
+ log = logging.getLogger(args[0].__module__)
+ if log.getEffectiveLevel() <= logging.INFO:
+ log.debug(''.join(text for text in args[1:]))
+
+
+def log_error(*args):
+ """
+ Log_error function with auto guard code.
+ Called by log_error(self, text1, text2 etc)
+
+ `args`
+ Values to be used. Expects self to be the first parameter
+ """
+ log = logging.getLogger(args[0].__module__)
+ if log.getEffectiveLevel() <= logging.ERROR:
+ log.error(''.join(text for text in args[1:]))
=== modified file 'openlp/core/ui/mainwindow.py'
--- openlp/core/ui/mainwindow.py 2013-10-13 21:07:28 +0000
+++ openlp/core/ui/mainwindow.py 2013-10-27 17:30:33 +0000
@@ -29,7 +29,6 @@
"""
This is the main window, where all the action happens.
"""
-import logging
import os
import sys
import shutil
@@ -47,14 +46,13 @@
from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \
MediaDockManager, ShortcutListForm, FormattingTagForm
-from openlp.core.common import AppLocation, Settings, check_directory_exists, translate
+from openlp.core.common import AppLocation, Settings, check_directory_exists, translate, trace, log_info, log_error, \
+ log_debug
from openlp.core.ui.media import MediaController
from openlp.core.utils import LanguageManager, add_actions, get_application_version
from openlp.core.utils.actions import ActionList, CategoryOrder
from openlp.core.ui.firsttimeform import FirstTimeForm
-log = logging.getLogger(__name__)
-
MEDIA_MANAGER_STYLE = """
QToolBox {
padding-bottom: 2px;
@@ -467,12 +465,11 @@
self.mode_live_item.setStatusTip(translate('OpenLP.MainWindow', 'Set the view mode to Live.'))
+@trace
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
"""
The main window.
"""
- log.info('MainWindow loaded')
-
def __init__(self):
"""
This constructor sets up the interface, the various managers, and the plugins.
@@ -551,7 +548,6 @@
"""
Called on start up to restore the last active media plugin.
"""
- log.info('Load data from Settings')
if Settings().value('advanced/save current plugin'):
saved_plugin_id = Settings().value('advanced/current media plugin')
if saved_plugin_id != -1:
@@ -581,7 +577,6 @@
Notifies the user that a newer version of OpenLP is available.
Triggered by delay thread and cannot display popup.
"""
- log.debug('version_notice')
version_text = translate('OpenLP.MainWindow', 'Version %s of OpenLP is now available for download (you are '
'currently running version %s). \n\nYou can download the latest version from http://openlp.org/.')
self.version_text = version_text % (version, get_application_version()['full'])
@@ -842,7 +837,7 @@
settings = Settings()
import_settings = Settings(temp_config, Settings.IniFormat)
# Convert image files
- log.info('hook upgrade_plugin_settings')
+ log_info(self, 'hook upgrade_plugin_settings')
self.plugin_manager.hook_upgrade_plugin_settings(import_settings)
# Remove/rename old settings to prepare the import.
import_settings.remove_obsolete_settings()
@@ -998,7 +993,6 @@
"""
The screen has changed so we have to update components such as the renderer.
"""
- log.debug('screen_changed')
self.application.set_busy_cursor()
self.image_manager.update_display()
self.renderer.update_display()
@@ -1065,7 +1059,7 @@
if Settings().value('advanced/save current plugin'):
Settings().setValue('advanced/current media plugin', self.media_tool_box.currentIndex())
# Call the cleanup method to shutdown plugins.
- log.info('cleanup plugins')
+ log_info(self, 'Cleanup plugins')
self.plugin_manager.finalise_plugins()
if save_settings:
# Save settings
@@ -1182,7 +1176,6 @@
"""
Load the main window settings.
"""
- log.debug('Loading QSettings')
settings = Settings()
# Remove obsolete entries.
settings.remove('custom slide')
@@ -1209,7 +1202,6 @@
# Exit if we just did a settings import.
if self.settingsImported:
return
- log.debug('Saving QSettings')
settings = Settings()
settings.beginGroup(self.general_settings_section)
settings.setValue('recent files', self.recent_files)
@@ -1233,7 +1225,7 @@
recent_files_to_display = existing_recent_files[0:recent_file_count]
self.recent_files_menu.clear()
for file_id, filename in enumerate(recent_files_to_display):
- log.debug('Recent file name: %s', filename)
+ log_debug(self, 'Recent file name: %s', filename)
action = create_action(self, '',
text='&%d %s' % (file_id + 1, os.path.splitext(os.path.basename(
str(filename)))[0]), data=filename,
@@ -1335,28 +1327,28 @@
"""
Change the data directory.
"""
- log.info('Changing data path to %s' % self.new_data_path)
+ log_info(self, 'Changing data path to %s' % self.new_data_path)
old_data_path = str(AppLocation.get_data_path())
# Copy OpenLP data to new location if requested.
self.application.set_busy_cursor()
if self.copy_data:
- log.info('Copying data to new path')
+ log_info(self, 'Copying data to new path')
try:
self.showStatusMessage(
translate('OpenLP.MainWindow', 'Copying OpenLP data to new data directory location - %s '
'- Please wait for copy to finish').replace('%s', self.new_data_path))
dir_util.copy_tree(old_data_path, self.new_data_path)
- log.info('Copy sucessful')
+ log_info(self, 'Copy sucessful')
except (IOError, os.error, DistutilsFileError) as why:
self.application.set_normal_cursor()
- log.exception('Data copy failed %s' % str(why))
+ log_error(self, 'Data copy failed %s' % str(why))
QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'New Data Directory Error'),
translate('OpenLP.MainWindow',
'OpenLP Data directory copy failed\n\n%s').replace('%s', str(why)),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return False
else:
- log.info('No data copy requested')
+ log_info(self, 'No data copy requested')
# Change the location of data directory in config file.
settings = QtCore.QSettings()
settings.setValue('advanced/data path', self.new_data_path)
Follow ups