summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-04-10 17:15:14 +0000
committerGerrit Code Review <review@openstack.org>2018-04-10 17:15:14 +0000
commit42e50ea2a0a261df0493569d7001038280f9ea03 (patch)
treead0d536f6dd99fee2b63f62d2044700ba9641a50
parentb1aa2ad3350044b7f2f4109d9018acbaef694b63 (diff)
parenta6ac975f7786052c73fb970c0420d956b2852e6e (diff)
downloadpython-barbicanclient-42e50ea2a0a261df0493569d7001038280f9ea03.tar.gz
Merge "Supress client debug messages"
-rw-r--r--barbicanclient/barbican.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/barbicanclient/barbican.py b/barbicanclient/barbican.py
index e26eb34..a462f1d 100644
--- a/barbicanclient/barbican.py
+++ b/barbicanclient/barbican.py
@@ -46,6 +46,13 @@ _IDENTITY_API_VERSION_3 = ['3']
class Barbican(app.App):
"""Barbican command line interface."""
+ # verbose logging levels
+ WARNING_LEVEL = 0
+ INFO_LEVEL = 1
+ DEBUG_LEVEL = 2
+ CONSOLE_MESSAGE_FORMAT = '%(message)s'
+ DEBUG_MESSAGE_FORMAT = '%(levelname)s: %(name)s %(message)s'
+
def __init__(self, **kwargs):
self.client = None
@@ -328,6 +335,9 @@ class Barbican(app.App):
"""
self.client_manager = namedtuple('ClientManager', 'key_manager')
if cmd.auth_required:
+ # NOTE(liujiong): cliff sets log level to DEBUG in run function,
+ # need to overwrite this configuration to depress DEBUG messages.
+ self.configure_logging()
self.client_manager.key_manager = self.create_client(self.options)
def run(self, argv):
@@ -337,6 +347,26 @@ class Barbican(app.App):
return 1
return super(Barbican, self).run(argv)
+ def configure_logging(self):
+ """Create logging handlers for any log output."""
+ root_logger = logging.getLogger('')
+ # Set log level to INFO
+ root_logger.setLevel(logging.INFO)
+
+ # Send higher-level messages to the console via stderr
+ console = logging.StreamHandler(self.stderr)
+ console_level = {self.WARNING_LEVEL: logging.WARNING,
+ self.INFO_LEVEL: logging.INFO,
+ self.DEBUG_LEVEL: logging.DEBUG,
+ }.get(self.options.verbose_level, logging.INFO)
+ if logging.DEBUG == console_level:
+ formatter = logging.Formatter(self.DEBUG_MESSAGE_FORMAT)
+ else:
+ formatter = logging.Formatter(self.CONSOLE_MESSAGE_FORMAT)
+ console.setFormatter(formatter)
+ root_logger.addHandler(console)
+ return
+
def main(argv=sys.argv[1:]):
logging.basicConfig()