diff --git a/paunch/cmd.py b/paunch/cmd.py index 31ab012..157459e 100644 --- a/paunch/cmd.py +++ b/paunch/cmd.py @@ -20,6 +20,9 @@ import yaml import paunch +from paunch import constants +from paunch import utils + class Apply(command.Command): @@ -62,8 +65,9 @@ class Apply(command.Command): # takes 1, or 2 if --verbose, or 4 - 5 if --debug log_level = (self.app_args.verbose_level + int(self.app_args.debug) * 3) - self.log = paunch.utils.common.configure_logging( - __name__, log_level, self.app_args.log_file) + log_file = self.app_args.log_file or constants.LOG_FILE + self.log = utils.common.configure_logging( + __name__, log_level, log_file) labels = collections.OrderedDict() for l in parsed_args.labels: k, v = l.split(('='), 1) @@ -78,7 +82,7 @@ class Apply(command.Command): managed_by='paunch', labels=labels, log_level=log_level, - log_file=self.app_args.log_file + log_file=log_file ) return rc @@ -110,13 +114,14 @@ class Cleanup(command.Command): # takes 1, or 2 if --verbose, or 4 - 5 if --debug log_level = (self.app_args.verbose_level + int(self.app_args.debug) * 3) - self.log = paunch.utils.common.configure_logging( - __name__, log_level, self.app_args.log_file) + log_file = self.app_args.log_file or constants.LOG_FILE + self.log = utils.common.configure_logging( + __name__, log_level, log_file) paunch.cleanup( parsed_args.config_id, managed_by=parsed_args.managed_by, log_level=log_level, - log_file=self.app_args.log_file + log_file=log_file ) @@ -145,13 +150,14 @@ class Delete(command.Command): # takes 1, or 2 if --verbose, or 4 - 5 if --debug log_level = (self.app_args.verbose_level + int(self.app_args.debug) * 3) - self.log = paunch.utils.common.configure_logging( - __name__, log_level, self.app_args.log_file) + log_file = self.app_args.log_file or constants.LOG_FILE + self.log = utils.common.configure_logging( + __name__, log_level, log_file) paunch.delete( parsed_args.config_id, parsed_args.managed_by, log_level=log_level, - log_file=self.app_args.log_file + log_file=log_file ) @@ -242,8 +248,10 @@ class Debug(command.Command): # takes 1, or 2 if --verbose, or 4 - 5 if --debug log_level = (self.app_args.verbose_level + int(self.app_args.debug) * 3) - self.log = paunch.utils.common.configure_logging( - __name__, log_level, self.app_args.log_file) + # Only log to a file if explicitely set via CLI args + log_file = self.app_args.log_file + self.log = utils.common.configure_logging( + __name__, log_level, log_file) labels = collections.OrderedDict() for l in parsed_args.labels: k, v = l.split(('='), 1) @@ -286,7 +294,7 @@ class Debug(command.Command): parsed_args.managed_by, labels=labels, log_level=log_level, - log_file=self.app_args.log_file + log_file=log_file ) @@ -309,12 +317,13 @@ class List(lister.Lister): # takes 1, or 2 if --verbose, or 4 - 5 if --debug log_level = (self.app_args.verbose_level + int(self.app_args.debug) * 3) - self.log = paunch.utils.common.configure_logging( - __name__, log_level, self.app_args.log_file) + log_file = self.app_args.log_file or constants.LOG_FILE + self.log = utils.common.configure_logging( + __name__, log_level, log_file) configs = paunch.list( parsed_args.managed_by, log_level=log_level, - log_file=self.app_args.log_file + log_file=log_file ) columns = [ 'config', diff --git a/paunch/constants.py b/paunch/constants.py new file mode 100644 index 0000000..c96567c --- /dev/null +++ b/paunch/constants.py @@ -0,0 +1,16 @@ +# Copyright 2018 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +LOG_FILE = '/var/log/paunch.log'