Merge "Move set warnings filters to logging module"
This commit is contained in:
commit
1a2bb48432
openstackclient
@ -14,6 +14,7 @@
|
|||||||
"""Context and Formatter"""
|
"""Context and Formatter"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import warnings
|
||||||
|
|
||||||
_LOG_MESSAGE_FORMAT = ('%(asctime)s.%(msecs)03d %(process)d '
|
_LOG_MESSAGE_FORMAT = ('%(asctime)s.%(msecs)03d %(process)d '
|
||||||
'%(levelname)s %(name)s [%(clouds_name)s '
|
'%(levelname)s %(name)s [%(clouds_name)s '
|
||||||
@ -21,6 +22,15 @@ _LOG_MESSAGE_FORMAT = ('%(asctime)s.%(msecs)03d %(process)d '
|
|||||||
_LOG_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
|
_LOG_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
|
||||||
|
|
||||||
|
|
||||||
|
def set_warning_filter(log_level):
|
||||||
|
if log_level == logging.ERROR:
|
||||||
|
warnings.simplefilter("ignore")
|
||||||
|
elif log_level == logging.WARNING:
|
||||||
|
warnings.simplefilter("ignore")
|
||||||
|
elif log_level == logging.INFO:
|
||||||
|
warnings.simplefilter("once")
|
||||||
|
|
||||||
|
|
||||||
def setup_handler_logging_level(handler_type, level):
|
def setup_handler_logging_level(handler_type, level):
|
||||||
"""Setup of the handler for set the logging level
|
"""Setup of the handler for set the logging level
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import getpass
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import warnings
|
|
||||||
|
|
||||||
from cliff import app
|
from cliff import app
|
||||||
from cliff import command
|
from cliff import command
|
||||||
@ -117,18 +116,16 @@ class OpenStackShell(app.App):
|
|||||||
if self.options.verbose_level == 0:
|
if self.options.verbose_level == 0:
|
||||||
# --quiet
|
# --quiet
|
||||||
log_level = logging.ERROR
|
log_level = logging.ERROR
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
elif self.options.verbose_level == 1:
|
elif self.options.verbose_level == 1:
|
||||||
# This is the default case, no --debug, --verbose or --quiet
|
# This is the default case, no --debug, --verbose or --quiet
|
||||||
log_level = logging.WARNING
|
log_level = logging.WARNING
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
elif self.options.verbose_level == 2:
|
elif self.options.verbose_level == 2:
|
||||||
# One --verbose
|
# One --verbose
|
||||||
log_level = logging.INFO
|
log_level = logging.INFO
|
||||||
warnings.simplefilter("once")
|
|
||||||
elif self.options.verbose_level >= 3:
|
elif self.options.verbose_level >= 3:
|
||||||
# Two or more --verbose
|
# Two or more --verbose
|
||||||
log_level = logging.DEBUG
|
log_level = logging.DEBUG
|
||||||
|
context.set_warning_filter(log_level)
|
||||||
|
|
||||||
# Set the handler logging level of FileHandler(--log-file)
|
# Set the handler logging level of FileHandler(--log-file)
|
||||||
# and StreamHandler
|
# and StreamHandler
|
||||||
|
@ -62,6 +62,15 @@ class TestContext(utils.TestCase):
|
|||||||
context.setup_logging(shell, cloud_config)
|
context.setup_logging(shell, cloud_config)
|
||||||
self.assertEqual(True, shell.enable_operation_logging)
|
self.assertEqual(True, shell.enable_operation_logging)
|
||||||
|
|
||||||
|
@mock.patch('warnings.simplefilter')
|
||||||
|
def test_set_warning_filter(self, simplefilter):
|
||||||
|
context.set_warning_filter(logging.ERROR)
|
||||||
|
simplefilter.assert_called_with("ignore")
|
||||||
|
context.set_warning_filter(logging.WARNING)
|
||||||
|
simplefilter.assert_called_with("ignore")
|
||||||
|
context.set_warning_filter(logging.INFO)
|
||||||
|
simplefilter.assert_called_with("once")
|
||||||
|
|
||||||
|
|
||||||
class Test_LogContext(utils.TestCase):
|
class Test_LogContext(utils.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user