diff --git a/collectd_ceilometer/aodh/plugin.py b/collectd_ceilometer/aodh/plugin.py index 7b33ea3..0350467 100644 --- a/collectd_ceilometer/aodh/plugin.py +++ b/collectd_ceilometer/aodh/plugin.py @@ -39,10 +39,9 @@ def register_plugin(collectd): config = Config.instance() # Setup loggging - log_handler = CollectdLogHandler(collectd=collectd) - log_handler.cfg = config + log_handler = CollectdLogHandler(collectd=collectd, config=config) ROOT_LOGGER.addHandler(log_handler) - ROOT_LOGGER.setLevel(logging.NOTSET) + ROOT_LOGGER.setLevel(logging.DEBUG) # Creates collectd plugin instance instance = Plugin(collectd=collectd, config=config) diff --git a/collectd_ceilometer/ceilometer/plugin.py b/collectd_ceilometer/ceilometer/plugin.py index 8c47ce2..51277ce 100644 --- a/collectd_ceilometer/ceilometer/plugin.py +++ b/collectd_ceilometer/ceilometer/plugin.py @@ -39,10 +39,9 @@ def register_plugin(collectd): config = Config.instance() # Setup loggging - log_handler = CollectdLogHandler(collectd=collectd) - log_handler.cfg = config + log_handler = CollectdLogHandler(collectd=collectd, config=config) ROOT_LOGGER.addHandler(log_handler) - ROOT_LOGGER.setLevel(logging.NOTSET) + ROOT_LOGGER.setLevel(logging.DEBUG) # Creates collectd plugin instance instance = Plugin(collectd=collectd, config=config) diff --git a/collectd_ceilometer/common/logger.py b/collectd_ceilometer/common/logger.py index 6b0d607..b5b7f6b 100644 --- a/collectd_ceilometer/common/logger.py +++ b/collectd_ceilometer/common/logger.py @@ -24,10 +24,9 @@ class CollectdLogHandler(logging.Handler): # messages longer than this size have to be split max_message_length = 1023 - verbose = False - - def __init__(self, collectd, level=logging.NOTSET): + def __init__(self, collectd, config, level=logging.NOTSET): super(CollectdLogHandler, self).__init__(level=level) + self.cfg = config self.priority_map = { logging.DEBUG: collectd.debug, logging.INFO: collectd.info, @@ -51,7 +50,7 @@ class CollectdLogHandler(logging.Handler): level=logging.ERROR) def emit_message(self, message, level): - if self.verbose and level == logging.DEBUG: + if self.cfg.VERBOSE and level == logging.DEBUG: level = logging.INFO elif level not in self.priority_map: level = logging.ERROR diff --git a/collectd_ceilometer/gnocchi/plugin.py b/collectd_ceilometer/gnocchi/plugin.py index 0a60e79..81ff90f 100644 --- a/collectd_ceilometer/gnocchi/plugin.py +++ b/collectd_ceilometer/gnocchi/plugin.py @@ -38,10 +38,9 @@ def register_plugin(collectd): config = Config.instance() # Setup loggging - log_handler = CollectdLogHandler(collectd=collectd) - log_handler.cfg = config + log_handler = CollectdLogHandler(collectd=collectd, config=config) ROOT_LOGGER.addHandler(log_handler) - ROOT_LOGGER.setLevel(logging.NOTSET) + ROOT_LOGGER.setLevel(logging.DEBUG) # Creates collectd plugin instance instance = Plugin(collectd=collectd, config=config) diff --git a/collectd_ceilometer/tests/aodh/test_plugin.py b/collectd_ceilometer/tests/aodh/test_plugin.py index 03476fb..58102ae 100644 --- a/collectd_ceilometer/tests/aodh/test_plugin.py +++ b/collectd_ceilometer/tests/aodh/test_plugin.py @@ -182,7 +182,7 @@ class TestPlugin(unittest.TestCase): # Logger handler is set up ROOT_LOGGER.addHandler.assert_called_once_with( CollectdLogHandler.return_value) - ROOT_LOGGER.setLevel.assert_called_once_with(logging.NOTSET) + ROOT_LOGGER.setLevel.assert_called_once_with(logging.DEBUG) # It creates a plugin Plugin.assert_called_once_with( diff --git a/collectd_ceilometer/tests/ceilometer/test_plugin.py b/collectd_ceilometer/tests/ceilometer/test_plugin.py index 95b87a5..c7a1c26 100644 --- a/collectd_ceilometer/tests/ceilometer/test_plugin.py +++ b/collectd_ceilometer/tests/ceilometer/test_plugin.py @@ -130,7 +130,7 @@ class TestPlugin(unittest.TestCase): # Logger handler is set up ROOT_LOGGER.addHandler.assert_called_once_with( CollectdLogHandler.return_value) - ROOT_LOGGER.setLevel.assert_called_once_with(logging.NOTSET) + ROOT_LOGGER.setLevel.assert_called_once_with(logging.DEBUG) # It create a plugin Plugin.assert_called_once_with( diff --git a/collectd_ceilometer/tests/common/test_logger.py b/collectd_ceilometer/tests/common/test_logger.py index dac64b6..dc757d1 100644 --- a/collectd_ceilometer/tests/common/test_logger.py +++ b/collectd_ceilometer/tests/common/test_logger.py @@ -17,7 +17,7 @@ import unittest import mock from collectd_ceilometer.common.logger import CollectdLogHandler - +from collectd_ceilometer.common.settings import Config from collectd_ceilometer.tests.mocking import patch_class @@ -48,11 +48,16 @@ def make_record( class TestCollectdLogHandler(unittest.TestCase): + def __init__(self, *args, **kwargs): + """Declare additional class attributes""" + super(TestCollectdLogHandler, self).__init__(*args, **kwargs) + self.config = Config.instance() + @patch_class(MockedCollectd) def test_registered_hooks_when_init(self, collectd): # When CollectdLogHandler is created - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) # Then collectd logging hooks are registered # pylint: disable=protected-access @@ -68,7 +73,7 @@ class TestCollectdLogHandler(unittest.TestCase): def test_debug_when_emit(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) record = make_record(msg="message", level=logging.DEBUG) # When a debug record is emitted @@ -80,8 +85,8 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_verbose_debug_when_emit(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) - handler.verbose = True + handler = CollectdLogHandler(collectd=collectd, config=self.config) + self.config.VERBOSE = True record = make_record(msg="message", level=logging.DEBUG) # When an info record is emitted @@ -93,7 +98,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_info_when_emit(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) record = make_record(msg="message", level=logging.INFO) # When an info record is emitted @@ -105,7 +110,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_warning_when_emit(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) record = make_record(msg="message", level=logging.WARNING) # When a warning record is emitted @@ -117,7 +122,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_error_when_emit(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) record = make_record(msg="message", level=logging.ERROR) # When an error record is emitted @@ -129,7 +134,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_fatal_when_emit(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) record = make_record(msg="message", level=logging.FATAL) # When a fatal record is emitted @@ -142,7 +147,7 @@ class TestCollectdLogHandler(unittest.TestCase): def test_long_message_when_emit(self, collectd): # Given long_message = "LONG " * 20 + "MESSAGE." - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) handler.max_message_length = 10 record = make_record(msg=long_message) @@ -157,11 +162,12 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_when_logger_debug(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) logger = logging.Logger('some_logger') logger.addHandler(handler) # When debug is called + self.config.VERBOSE = False logger.debug('Say cheese: %s %d', 'string', 10) # Then debug hook is called @@ -171,12 +177,12 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_verbose_when_logger_info(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) - handler.verbose = True + handler = CollectdLogHandler(collectd=collectd, config=self.config) logger = logging.Logger('some_logger') logger.addHandler(handler) # When debug is called + self.config.VERBOSE = True logger.debug('Say cheese: %s %d', 'string', 10) # Then info hook is called @@ -186,7 +192,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_non_verbose_when_logger_info(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) handler.verbose = False logger = logging.Logger('some_logger') logger.addHandler(handler) @@ -201,7 +207,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_info_from_logger(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) logger = logging.Logger('some_logger') logger.addHandler(handler) @@ -214,7 +220,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_warning_from_logger(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) logger = logging.Logger('some_logger') logger.addHandler(handler) @@ -227,7 +233,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_error_from_logger(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) logger = logging.Logger('some_logger') logger.addHandler(handler) @@ -240,7 +246,7 @@ class TestCollectdLogHandler(unittest.TestCase): @patch_class(MockedCollectd) def test_fatal_from_logger(self, collectd): # Given - handler = CollectdLogHandler(collectd=collectd) + handler = CollectdLogHandler(collectd=collectd, config=self.config) logger = logging.Logger('some_logger') logger.addHandler(handler) diff --git a/collectd_ceilometer/tests/gnocchi/test_plugin.py b/collectd_ceilometer/tests/gnocchi/test_plugin.py index f2df1e9..9a3aec9 100644 --- a/collectd_ceilometer/tests/gnocchi/test_plugin.py +++ b/collectd_ceilometer/tests/gnocchi/test_plugin.py @@ -127,7 +127,7 @@ class TestPlugin(unittest.TestCase): # Logger handler is set up ROOT_LOGGER.addHandler.assert_called_once_with( CollectdLogHandler.return_value) - ROOT_LOGGER.setLevel.assert_called_once_with(logging.NOTSET) + ROOT_LOGGER.setLevel.assert_called_once_with(logging.DEBUG) # It create a plugin Plugin.assert_called_once_with( diff --git a/doc/source/examples/local.conf.minimal b/doc/source/examples/local.conf.minimal index 9013f93..5c6f6de 100644 --- a/doc/source/examples/local.conf.minimal +++ b/doc/source/examples/local.conf.minimal @@ -27,5 +27,5 @@ CEILOMETER_BACKEND=mysql enable_plugin collectd-ceilometer https://github.com/openstack/collectd-ceilometer-plugin COLLECTD_INSTALL=True -COLLECTD_CEILOMETER_VERBOSE=True +COLLECTD_CEILOMETER_VERBOSE=False COLLECTD_CEILOMETER_ENABLED=True diff --git a/etc/collectd.conf.d/collectd-gnocchi-plugin.conf b/etc/collectd.conf.d/collectd-gnocchi-plugin.conf index f28f638..6f86c4a 100644 --- a/etc/collectd.conf.d/collectd-gnocchi-plugin.conf +++ b/etc/collectd.conf.d/collectd-gnocchi-plugin.conf @@ -11,7 +11,7 @@ # Verbosity True|False - VERBOSE True + VERBOSE False # Batch size BATCH_SIZE "1" diff --git a/local.conf b/local.conf index 15a79a2..f922cde 100644 --- a/local.conf +++ b/local.conf @@ -15,5 +15,5 @@ enable_plugin "ceilometer" "${GIT_BASE:-https://git.openstack.org}/openstack/cei # Setup collectd-ceilometer plugin COLLECTD_INSTALL=True -COLLECTD_CEILOMETER_VERBOSE=True +COLLECTD_CEILOMETER_VERBOSE=False enable_plugin "collectd-ceilometer-plugin" "${GIT_BASE:-https://git.openstack.org}/openstack/collectd-ceilometer-plugin.git" diff --git a/releasenotes/notes/bug-1664937-0ae3be29c6f4df97.yaml b/releasenotes/notes/bug-1664937-0ae3be29c6f4df97.yaml new file mode 100644 index 0000000..ade6001 --- /dev/null +++ b/releasenotes/notes/bug-1664937-0ae3be29c6f4df97.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - Fixes bug 'https://launchpad.net/bugs/1664973' + VERBOSE parameter is read and used again + Initial log level was fixed, so configuration is properly logged. + Initial VERBOSE changed to False, to avoid too much verbosity.