Log to a file by default, unless debugging

By default, log paunch to /var/log/paunch.log.

Related-Bug: #1799182

Change-Id: Ib0685eb72becb867452bef17f17ab8e3d5b7d931
Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
(cherry picked from commit 791766596c)
This commit is contained in:
Bogdan Dobrelya 2018-10-30 11:04:32 +01:00
parent 059aa8c1f6
commit 1c590fc76d
2 changed files with 40 additions and 15 deletions

View File

@ -20,6 +20,9 @@ import yaml
import paunch import paunch
from paunch import constants
from paunch import utils
class Apply(command.Command): class Apply(command.Command):
@ -62,8 +65,9 @@ class Apply(command.Command):
# takes 1, or 2 if --verbose, or 4 - 5 if --debug # takes 1, or 2 if --verbose, or 4 - 5 if --debug
log_level = (self.app_args.verbose_level + log_level = (self.app_args.verbose_level +
int(self.app_args.debug) * 3) int(self.app_args.debug) * 3)
self.log = paunch.utils.common.configure_logging( log_file = self.app_args.log_file or constants.LOG_FILE
__name__, log_level, self.app_args.log_file) self.log = utils.common.configure_logging(
__name__, log_level, log_file)
labels = collections.OrderedDict() labels = collections.OrderedDict()
for l in parsed_args.labels: for l in parsed_args.labels:
k, v = l.split(('='), 1) k, v = l.split(('='), 1)
@ -78,7 +82,7 @@ class Apply(command.Command):
managed_by='paunch', managed_by='paunch',
labels=labels, labels=labels,
log_level=log_level, log_level=log_level,
log_file=self.app_args.log_file log_file=log_file
) )
return rc return rc
@ -110,13 +114,14 @@ class Cleanup(command.Command):
# takes 1, or 2 if --verbose, or 4 - 5 if --debug # takes 1, or 2 if --verbose, or 4 - 5 if --debug
log_level = (self.app_args.verbose_level + log_level = (self.app_args.verbose_level +
int(self.app_args.debug) * 3) int(self.app_args.debug) * 3)
self.log = paunch.utils.common.configure_logging( log_file = self.app_args.log_file or constants.LOG_FILE
__name__, log_level, self.app_args.log_file) self.log = utils.common.configure_logging(
__name__, log_level, log_file)
paunch.cleanup( paunch.cleanup(
parsed_args.config_id, parsed_args.config_id,
managed_by=parsed_args.managed_by, managed_by=parsed_args.managed_by,
log_level=log_level, 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 # takes 1, or 2 if --verbose, or 4 - 5 if --debug
log_level = (self.app_args.verbose_level + log_level = (self.app_args.verbose_level +
int(self.app_args.debug) * 3) int(self.app_args.debug) * 3)
self.log = paunch.utils.common.configure_logging( log_file = self.app_args.log_file or constants.LOG_FILE
__name__, log_level, self.app_args.log_file) self.log = utils.common.configure_logging(
__name__, log_level, log_file)
paunch.delete( paunch.delete(
parsed_args.config_id, parsed_args.config_id,
parsed_args.managed_by, parsed_args.managed_by,
log_level=log_level, 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 # takes 1, or 2 if --verbose, or 4 - 5 if --debug
log_level = (self.app_args.verbose_level + log_level = (self.app_args.verbose_level +
int(self.app_args.debug) * 3) int(self.app_args.debug) * 3)
self.log = paunch.utils.common.configure_logging( # Only log to a file if explicitely set via CLI args
__name__, log_level, self.app_args.log_file) log_file = self.app_args.log_file
self.log = utils.common.configure_logging(
__name__, log_level, log_file)
labels = collections.OrderedDict() labels = collections.OrderedDict()
for l in parsed_args.labels: for l in parsed_args.labels:
k, v = l.split(('='), 1) k, v = l.split(('='), 1)
@ -286,7 +294,7 @@ class Debug(command.Command):
parsed_args.managed_by, parsed_args.managed_by,
labels=labels, labels=labels,
log_level=log_level, 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 # takes 1, or 2 if --verbose, or 4 - 5 if --debug
log_level = (self.app_args.verbose_level + log_level = (self.app_args.verbose_level +
int(self.app_args.debug) * 3) int(self.app_args.debug) * 3)
self.log = paunch.utils.common.configure_logging( log_file = self.app_args.log_file or constants.LOG_FILE
__name__, log_level, self.app_args.log_file) self.log = utils.common.configure_logging(
__name__, log_level, log_file)
configs = paunch.list( configs = paunch.list(
parsed_args.managed_by, parsed_args.managed_by,
log_level=log_level, log_level=log_level,
log_file=self.app_args.log_file log_file=log_file
) )
columns = [ columns = [
'config', 'config',

16
paunch/constants.py Normal file
View File

@ -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'