← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~elderp/openlp/logfile-bug-1020068 into lp:openlp

 

Stevan Pettit has proposed merging lp:~elderp/openlp/logfile-bug-1020068 into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)

For more details, see:
https://code.launchpad.net/~elderp/openlp/logfile-bug-1020068/+merge/113870

Added code to put logfile into portableapp-dir/other if running portable.

Fixed procedure name
-- 
https://code.launchpad.net/~elderp/openlp/logfile-bug-1020068/+merge/113870
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/__init__.py'
--- openlp/core/__init__.py	2012-06-22 14:14:53 +0000
+++ openlp/core/__init__.py	2012-07-08 19:36:23 +0000
@@ -207,6 +207,16 @@
         else:
             return QtGui.QApplication.event(self, event)
 
+def set_up_logging(log_path):
+    """
+    Setup our logging using log_path
+    """
+    check_directory_exists(log_path)
+    filename = os.path.join(log_path, u'openlp.log')
+    logfile = logging.FileHandler(filename, u'w')
+    logfile.setFormatter(logging.Formatter(
+        u'%(asctime)s %(name)-55s %(levelname)-8s %(message)s'))
+    log.addHandler(logfile)
 
 def main(args=None):
     """
@@ -231,14 +241,6 @@
         help='Set the Qt4 style (passed directly to Qt4).')
     parser.add_option('--testing', dest='testing',
         action='store_true', help='Run by testing framework')
-    # Set up logging
-    log_path = AppLocation.get_directory(AppLocation.CacheDir)
-    check_directory_exists(log_path)
-    filename = os.path.join(log_path, u'openlp.log')
-    logfile = logging.FileHandler(filename, u'w')
-    logfile.setFormatter(logging.Formatter(
-        u'%(asctime)s %(name)-55s %(levelname)-8s %(message)s'))
-    log.addHandler(logfile)
     # Parse command line options and deal with them.
     # Use args supplied programatically if possible.
     (options, args) = parser.parse_args(args) if args else parser.parse_args()
@@ -261,11 +263,13 @@
     app.setOrganizationName(u'OpenLP')
     app.setOrganizationDomain(u'openlp.org')
     if options.portable:
-        log.info(u'Running portable')
         app.setApplicationName(u'OpenLPPortable')
         Settings.setDefaultFormat(Settings.IniFormat)
         # Get location OpenLPPortable.ini
         app_path = AppLocation.get_directory(AppLocation.AppDir)
+        set_up_logging(os.path.abspath(os.path.join(app_path, u'..',
+            u'..', u'Other')))
+        log.info(u'Running portable')
         portable_settings_file = os.path.abspath(os.path.join(app_path, u'..',
             u'..', u'Data', u'OpenLP.ini'))
         # Make this our settings file
@@ -282,6 +286,8 @@
         portable_settings.sync()
     else:
         app.setApplicationName(u'OpenLP')
+        # Set up logging
+        set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
     app.setApplicationVersion(get_application_version()[u'version'])
     # Instance check
     if not options.testing:


Follow ups