diff options
| author | TerryHowe <terrylhowe@gmail.com> | 2015-08-10 12:33:28 -0600 |
|---|---|---|
| committer | Terry Howe <terrylhowe@gmail.com> | 2015-08-26 10:23:53 +0000 |
| commit | 85a03945f0b5da0ec5778a929e08a641f427513a (patch) | |
| tree | 1c3bcb525ed420bce2a993f8244c2a3db40a5df2 /openstackclient/shell.py | |
| parent | 6c46355734f7a7278b92645e6a465b6e38096daf (diff) | |
| download | python-openstackclient-85a03945f0b5da0ec5778a929e08a641f427513a.tar.gz | |
Create log configuration class
Configuration of logging gets triggered twice. The first time it
uses the CLI options when the application is started and second
it uses the configuration file after that is read. The state of
the logging needs to be saved from the first to the second time,
so I created a class.
Implements: blueprint logging-migration
Change-Id: I7b8d1a3b6fd128e98cafd7c16009c7b694a52146
Diffstat (limited to 'openstackclient/shell.py')
| -rw-r--r-- | openstackclient/shell.py | 61 |
1 files changed, 5 insertions, 56 deletions
diff --git a/openstackclient/shell.py b/openstackclient/shell.py index 6ba19d19..72f663a0 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -94,60 +94,12 @@ class OpenStackShell(app.App): self.verify = True self.client_manager = None - - # Operation log - self.enable_operation_logging = False self.command_options = None def configure_logging(self): - """Configure logging for the app - - Cliff sets some defaults we don't want so re-work it a bit - """ - - if self.options.debug: - # --debug forces verbose_level 3 - # Set this here so cliff.app.configure_logging() can work - self.options.verbose_level = 3 - - super(OpenStackShell, self).configure_logging() - - # Set logging to the requested level - log_level = context.log_level_from_options(self.options) - context.set_warning_filter(log_level) - - # Set the handler logging level of FileHandler(--log-file) - # and StreamHandler - if self.options.log_file: - context.setup_handler_logging_level(logging.FileHandler, log_level) - - context.setup_handler_logging_level(logging.StreamHandler, log_level) - - # Requests logs some stuff at INFO that we don't want - # unless we have DEBUG - requests_log = logging.getLogger("requests") - - # Other modules we don't want DEBUG output for - cliff_log = logging.getLogger('cliff') - stevedore_log = logging.getLogger('stevedore') - iso8601_log = logging.getLogger("iso8601") - - if self.options.debug: - # --debug forces traceback - self.dump_stack_trace = True - requests_log.setLevel(logging.DEBUG) - else: - self.dump_stack_trace = False - requests_log.setLevel(logging.ERROR) - - cliff_log.setLevel(logging.ERROR) - stevedore_log.setLevel(logging.ERROR) - iso8601_log.setLevel(logging.ERROR) - - # Operation logging - self.operation_log = logging.getLogger("operation_log") - self.operation_log.setLevel(logging.ERROR) - self.operation_log.propagate = False + """Configure logging for the app.""" + self.log_configurator = context.LogConfigurator(self.options) + self.dump_stack_trace = self.log_configurator.dump_trace def run(self, argv): ret_val = 1 @@ -162,8 +114,6 @@ class OpenStackShell(app.App): self.log.error(traceback.format_exc(e)) else: self.log.error('Exception raised: ' + str(e)) - if self.enable_operation_logging: - self.operation_log.error(traceback.format_exc(e)) return ret_val @@ -287,9 +237,8 @@ class OpenStackShell(app.App): argparse=self.options, ) - # Set up every time record log in file and logging start - context.setup_logging(self, self.cloud) - + self.log_configurator.configure(self.cloud) + self.dump_stack_trace = self.log_configurator.dump_trace self.log.info("START with options: %s", self.command_options) self.log.debug("options: %s", self.options) self.log.debug("defaults: %s", cc.defaults) |
