diff --git a/apiclient/lib/config.py b/apiclient/lib/config.py index 958696d..be39f86 100644 --- a/apiclient/lib/config.py +++ b/apiclient/lib/config.py @@ -116,6 +116,12 @@ def __init__(self, name, default_value = None, required = False, description = "The desired logging level. Choices are %s." % (", ".join(logcontrol.LOG_LEVELS), ) + ), + ConfigOption( + "show-tracebacks", default_value = False, + description = + "Whether to display trace backs when *expected* exceptions are " + "encountered." ) ] KNOWN_OPTIONS = dict((i.name, i) for i in __option_list) @@ -297,7 +303,6 @@ def load_config(): if os.path.isfile(i): config_file_path = i break - configuration = {} if config_file_path is None: logger.info("No configuration file found.") @@ -336,7 +341,7 @@ def load_config(): # Make a dictionary with the default values in it default_configuration = dict( (i.name, i.default_value) for i in KNOWN_OPTIONS.values() - if i.default_value + if i.default_value is not None ) # Join the various dictionaries we have together. Priority is bottom-to-top. diff --git a/apiclient/lib/logcontrol.py b/apiclient/lib/logcontrol.py index 7252549..f31264b 100644 --- a/apiclient/lib/logcontrol.py +++ b/apiclient/lib/logcontrol.py @@ -28,6 +28,8 @@ import logging logger = logging.getLogger("apiclient.logcontrol") +show_tracebacks = False + class LogFormatter(logging.Formatter): COLOR_MAP = { "DEBUG": "dark gray", @@ -51,7 +53,7 @@ def format(self, record): result.append(record.msg % record.args) - if record.exc_info: + if record.exc_info and show_tracebacks: if type(record.exc_info) is tuple: result.append("\n" + self.formatException(record.exc_info)) else: diff --git a/apiclient/main.py b/apiclient/main.py index 8cfa732..e9b9d7c 100755 --- a/apiclient/main.py +++ b/apiclient/main.py @@ -38,6 +38,7 @@ def main(): "Final configuration dictionary...\n%s", pprint.pformat(config.CONFIG, width = 72) ) + lib.logcontrol.show_tracebacks = config.CONFIG["show-tracebacks"] # Set to True by any of the "do something and exit" options. exit_now = False