def register(cls): assert collectd is not None LOG.info("Register plugin: %s", cls) log_handler = CollectdLogHandler(collectd=collectd) log_handler.setFormatter(logging.Formatter(LOG_FORMAT)) logging.getLogger('collectd_pandas').addHandler(log_handler) instance = cls() collectd.register_config(instance.configure) collectd.register_init(instance.initialize) collectd.register_write(instance.write) LOG.info("Plugin registered as: %r.", instance) return instance
def test_formatting_error(): # Given collectd = mock_collectd() handler = CollectdLogHandler(collectd=collectd) formatter = MagicMock(autospec=logging.Formatter) formatter.format.side_effect = RuntimeError handler.setFormatter(formatter) record = make_record(msg="message %s", level=logging.INFO) # When a warning record is emitted handler.emit(record=record) # Then info warning is called collectd.error.assert_called_once_with( wildcard("Error emitting message:\n" "Traceback (most recent call last):\n" "*\n" "RuntimeError\n"))