Skip to content

Commit

Permalink
Added option to print out exception info.
Browse files Browse the repository at this point in the history
* Suppressed by default.
* This is related to ucrcsedept/galah#356
  • Loading branch information
brownhead committed Sep 27, 2013
1 parent a9687cd commit 4a8517f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions apiclient/lib/config.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion apiclient/lib/logcontrol.py
Expand Up @@ -28,6 +28,8 @@
import logging
logger = logging.getLogger("apiclient.logcontrol")

show_tracebacks = False

class LogFormatter(logging.Formatter):
COLOR_MAP = {
"DEBUG": "dark gray",
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions apiclient/main.py
Expand Up @@ -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
Expand Down

0 comments on commit 4a8517f

Please sign in to comment.