summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-07-18 20:10:20 +0000
committerGerrit Code Review <review@openstack.org>2022-07-18 20:10:20 +0000
commit489bb43058d446a577377cff5828e98d13c79967 (patch)
tree5031288df7926c00e9444028122ff2bf7e9949e3
parentdfbd08f35fba7fdbcfce8241025dc8681d787e09 (diff)
parentbc753e22b465b9e711ad23c95a03977b5bc7347e (diff)
downloadpython-ironicclient-489bb43058d446a577377cff5828e98d13c79967.tar.gz
Merge "Fix logging in the baremetal CLI"
-rw-r--r--ironicclient/shell.py32
-rw-r--r--releasenotes/notes/logging-9c452e4869d80de9.yaml9
2 files changed, 32 insertions, 9 deletions
diff --git a/ironicclient/shell.py b/ironicclient/shell.py
index 22bf3a3..37892c5 100644
--- a/ironicclient/shell.py
+++ b/ironicclient/shell.py
@@ -170,21 +170,35 @@ class App(app.App):
)
return parser
+ # This is the openstacksdk default value
+ _STREAM_FORMAT = '%(asctime)s %(levelname)s: %(name)s %(message)s'
+
def _configure_ironic_logging(self):
- openstack.enable_logging(debug=self.options.debug)
- # NOTE(dtantsur): I wish logging.basicConfig worked.. but it does not.
+ debug_enabled = self.options.debug or self.options.verbose_level > 1
+
+ openstack.enable_logging(debug=debug_enabled, stream=sys.stderr,
+ format_template=self._STREAM_FORMAT,
+ # No fancy formatting if debug is off
+ format_stream=debug_enabled)
+ # NOTE(dtantsur): prevent openstack logging from appearing again in the
+ # cliff handlers
+ for name in ('openstack', 'keystoneauth'):
+ logger = logging.getLogger(name)
+ logger.propagate = False
+
+ # NOTE(dtantsur): I wish logging.basicConfig worked, but at this point
+ # cliff has already started configuring logging.
for name in ('ironicclient', 'ironic_inspector_client'):
logger = logging.getLogger(name)
logger.setLevel(
- logging.DEBUG if self.options.debug else logging.WARNING)
- # warnings are already configured by something else, only configure
+ logging.DEBUG if debug_enabled else logging.WARNING)
+ # warnings are already configured by cliff, only configure
# debug logging for ironic.
- if not logger.handlers and self.options.debug:
- handler = logging.StreamHandler()
- handler.setFormatter(logging.Formatter(
- # This is the openstacksdk default value
- '%(asctime)s %(levelname)s: %(name)s %(message)s'))
+ if not logger.handlers and debug_enabled:
+ handler = logging.StreamHandler(stream=sys.stderr)
+ handler.setFormatter(logging.Formatter(self._STREAM_FORMAT))
logger.addHandler(handler)
+ logger.propagate = False
def initialize_app(self, argv):
super(App, self).initialize_app(argv)
diff --git a/releasenotes/notes/logging-9c452e4869d80de9.yaml b/releasenotes/notes/logging-9c452e4869d80de9.yaml
new file mode 100644
index 0000000..24f2311
--- /dev/null
+++ b/releasenotes/notes/logging-9c452e4869d80de9.yaml
@@ -0,0 +1,9 @@
+---
+fixes:
+ - |
+ OpenStackSDK log messages are no longer sent to stdout and no longer break
+ parsing the output.
+ - |
+ The logging configuration now respects the ``--verbose`` flag.
+ - |
+ Some warnings are no longer duplicated.