From 5e5c9efd90af0958b98a0cf61fdafa0b4365d405 Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Mon, 20 Jun 2011 16:20:38 +0200 Subject: [PATCH] Enable logging --- sloth/core/cli.py | 6 +++--- sloth/core/labeltool.py | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sloth/core/cli.py b/sloth/core/cli.py index 904397c..ab42cde 100644 --- a/sloth/core/cli.py +++ b/sloth/core/cli.py @@ -81,9 +81,9 @@ class BaseCommand(object): """ # Metadata about this command. option_list = ( - #make_option('-v', '--verbosity', action='store', dest='verbosity', default='1', - #type='choice', choices=['0', '1', '2', '3'], - #help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), + make_option('-v', '--verbosity', action='store', dest='verbosity', default='2', + type='choice', choices=['0', '1', '2', '3', '4'], + help='Verbosity level; 0=critical, 1=error, 2=warning, 3=info, 4=debug'), make_option('-c', '--config', help='The Python path to a configuration file, e.g. "myconfig". If this isn\'t provided, sloth\'s default configuration will be used.'), make_option('--pythonpath', diff --git a/sloth/core/labeltool.py b/sloth/core/labeltool.py index 1c3481e..2f488d8 100755 --- a/sloth/core/labeltool.py +++ b/sloth/core/labeltool.py @@ -5,7 +5,7 @@ This is the core labeltool module. """ -import sys, os +import sys, os, logging from PyQt4.QtGui import * from PyQt4.QtCore import * from sloth.annotations.model import * @@ -99,6 +99,13 @@ class LabelTool(QObject): except: pass # Ignore any option errors at this point. + # Initialize logging + loglevel = (logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG)[int(options.verbosity)] + logging.basicConfig(level=loglevel) + + # Disable PyQt log messages + logging.getLogger("PyQt4").setLevel(logging.WARNING) + # Handle options common for all commands # and initialize the labeltool object from # the configuration (default config if not specified)