Added code to put logfile into appdir/other if running portable

This commit is contained in:
ElderP 2012-07-08 08:53:06 -04:00
parent 9d5fc7abf0
commit 8ad5fdad4a
1 changed files with 15 additions and 9 deletions

View File

@ -207,6 +207,16 @@ class OpenLP(QtGui.QApplication):
else:
return QtGui.QApplication.event(self, event)
def setupLogging(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 @@ def main(args=None):
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 @@ def main(args=None):
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)
setupLogging(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 @@ def main(args=None):
portable_settings.sync()
else:
app.setApplicationName(u'OpenLP')
# Set up logging
setupLogging(AppLocation.get_directory(AppLocation.CacheDir))
app.setApplicationVersion(get_application_version()[u'version'])
# Instance check
if not options.testing: