From 2633f2ee49c84a36e701c6b14562f59705b330bf Mon Sep 17 00:00:00 2001 From: Joe Portela Date: Tue, 4 Sep 2018 18:35:55 +0000 Subject: [PATCH 1/2] update logging for base cli --- base/services/cli.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/base/services/cli.py b/base/services/cli.py index 00613f2..4d80fe4 100644 --- a/base/services/cli.py +++ b/base/services/cli.py @@ -29,6 +29,15 @@ CLI_STOP_SIGNAL_FILE = '/tmp/APP_STOP_CLI' +log_file = ConfigManager().value('cli log file') +if log_file: + logging.basicConfig(filename = log_file) +else: + logging.basicConfig() + +# Obtain the root logger +logger = logging.getLogger() + # ----- Public Functions ----------------------------------------------------- def cli_main(function, args=None, stop_on_signal=True): @@ -45,7 +54,7 @@ def cli_main(function, args=None, stop_on_signal=True): try: function(cli) except Exception as e: - _handle_cli_exception_logging(e) + logger.exception(e) cli.set_status_error() tinyAPI.dsh().rollback(True) @@ -292,12 +301,3 @@ def header(title, width=79): body += ' ' * (width - 2 - len(body)) + "|\n" return enclosure + body + enclosure - -# ----- Private Functions ---------------------------------------------------- - -def _handle_cli_exception_logging(e): - log_file = ConfigManager().value('cli log file') - if log_file: - logging.basicConfig(filename = log_file) - logging.critical(traceback.format_exc()) - logging.shutdown() From 19a451f8a5fdea32f4cb0ad73d2ee40a630accbb Mon Sep 17 00:00:00 2001 From: Joe Portela Date: Tue, 4 Sep 2018 21:34:29 +0000 Subject: [PATCH 2/2] remove traceback import --- base/services/cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/base/services/cli.py b/base/services/cli.py index 4d80fe4..d3de368 100644 --- a/base/services/cli.py +++ b/base/services/cli.py @@ -17,7 +17,6 @@ import sys import time import tinyAPI -import traceback __all__ = [ 'CLI',