diff options
author | kali <kali@leap.se> | 2012-09-06 02:34:40 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-09-06 02:34:40 +0900 |
commit | bd26d30f34104898dd6c5314dee688e27c82529b (patch) | |
tree | 226ed4f238369f8937c28e3d0f11258cbfb7b506 /src/leap/app.py | |
parent | 6ef92e257ce1e605194cb26ff6cb804c7d2c3418 (diff) | |
parent | 8148bc9c8c113c41fcb18b397669b1f13447c653 (diff) |
Merge branch 'feature/error-handling' into develop
Closes #504: design generic error handling solution.
* app-wide logging config.
* --logfile command line argument.
* created basic exception hierarchy
* conductor pushes exceptions to error queue
* in Qt, error dialogs are created from exception attributes
Diffstat (limited to 'src/leap/app.py')
-rw-r--r-- | src/leap/app.py | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/leap/app.py b/src/leap/app.py index db48701b..5849848c 100644 --- a/src/leap/app.py +++ b/src/leap/app.py @@ -6,9 +6,6 @@ from PyQt4.QtGui import (QApplication, QSystemTrayIcon, QMessageBox) from leap.baseapp.mainwindow import LeapWindow -logging.basicConfig() -logger = logging.getLogger(name=__name__) - def main(): """ @@ -20,17 +17,39 @@ def main(): parser, opts = leap_argparse.init_leapc_args() debug = getattr(opts, 'debug', False) - #XXX get debug level and set logger accordingly + # XXX get severity from command line args if debug: - logger.setLevel('DEBUG') - logger.debug('args: %s' % opts) + level = logging.DEBUG + else: + level = logging.WARNING + + logger = logging.getLogger(name='leap') + logger.setLevel(level) + console = logging.StreamHandler() + console.setLevel(level) + formatter = logging.Formatter( + '%(asctime)s ' + '- %(name)s - %(levelname)s - %(message)s') + console.setFormatter(formatter) + logger.addHandler(console) + + logfile = getattr(opts, 'log_file', False) + if logfile: + logger.debug('setting logfile to %s ', logfile) + fileh = logging.FileHandler(logfile) + fileh.setLevel(logging.DEBUG) + fileh.setFormatter(formatter) + logger.addHandler(fileh) + + logger.debug('args: %s' % opts) + logger.info('Starting app') app = QApplication(sys.argv) if not QSystemTrayIcon.isSystemTrayAvailable(): QMessageBox.critical(None, "Systray", - "I couldn't detect any \ -system tray on this system.") + "I couldn't detect" + "any system tray on this system.") sys.exit(1) if not debug: QApplication.setQuitOnLastWindowClosed(False) |