Esempio n. 1
0
    def test_fatal_when_emit(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        record = make_record(msg="message", level=logging.FATAL)

        # When a fatal record is emitted
        handler.emit(record=record)

        # Then error hook is called
        collectd.error.assert_called_once_with("message")
Esempio n. 2
0
    def test_warning_when_emit(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        record = make_record(msg="message", level=logging.WARNING)

        # When a warning record is emitted
        handler.emit(record=record)

        # Then info warning is called
        collectd.warning.assert_called_once_with("message")
Esempio n. 3
0
    def test_info_when_emit(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        record = make_record(msg="message", level=logging.INFO)

        # When an info record is emitted
        handler.emit(record=record)

        # Then info hook is called
        collectd.info.assert_called_once_with("message")
Esempio n. 4
0
    def test_verbose_debug_when_emit(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        handler.verbose = True
        record = make_record(msg="message", level=logging.DEBUG)

        # When an info record is emitted
        handler.emit(record=record)

        # Then info hook is called
        collectd.info.assert_called_once_with("message")
Esempio n. 5
0
    def test_debug_when_emit(self, collectd):

        # Given
        handler = CollectdLogHandler(collectd=collectd)
        record = make_record(msg="message", level=logging.DEBUG)

        # When a debug record is emitted
        handler.emit(record=record)

        # Then debug hook is called
        collectd.debug.assert_called_once_with("message")
Esempio n. 6
0
    def test_non_verbose_when_logger_info(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        handler.verbose = False
        logger = logging.Logger('some_logger')
        logger.addHandler(handler)

        # When debug is called
        logger.debug('Say cheese: %s %d', 'string', 10)

        # Then debug hook is called
        collectd.debug.assert_called_once_with('Say cheese: string 10')
        collectd.info.assert_not_called()
Esempio n. 7
0
    def test_long_message_when_emit(self, collectd):
        # Given
        long_message = "LONG " * 20 + "MESSAGE."
        handler = CollectdLogHandler(collectd=collectd)
        handler.max_message_length = 10
        record = make_record(msg=long_message)

        # When a long message is emitted
        handler.emit(record=record)

        # Then info hook is called n times with split message
        collectd.info.assert_has_calls([
            mock.call(long_message[i:i + 10])
            for i in range(0, len(long_message), 10)
        ])
Esempio n. 8
0
    def test_fatal_from_logger(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        logger = logging.Logger('some_logger')
        logger.addHandler(handler)

        # When fatal is called
        logger.fatal('Say cheese: %s %d', 'string', 10)

        # Then error hook is called
        collectd.error.assert_called_once_with('Say cheese: string 10')
Esempio n. 9
0
    def test_warning_from_logger(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        logger = logging.Logger('some_logger')
        logger.addHandler(handler)

        # When warning is called
        logger.warning('Say cheese: %s %d', 'string', 10)

        # Then warning hook is called
        collectd.warning.assert_called_once_with('Say cheese: string 10')
Esempio n. 10
0
    def test_registered_hooks_when_init(self, collectd):

        # When CollectdLogHandler is created
        handler = CollectdLogHandler(collectd=collectd)

        # Then collectd logging hooks are registered
        # pylint: disable=protected-access
        self.assertEqual(
            {
                logging.DEBUG: collectd.debug,
                logging.INFO: collectd.info,
                logging.WARNING: collectd.warning,
                logging.ERROR: collectd.error,
                logging.FATAL: collectd.error
            }, handler.priority_map)
Esempio n. 11
0
# under the License.
"""Ceilometer collectd plugin"""

from __future__ import unicode_literals

# pylint: disable=import-error
import collectd
# pylint: enable=import-error

from collectd_ceilometer.logger import CollectdLogHandler
from collectd_ceilometer.meters import MeterStorage
from collectd_ceilometer.settings import Config
from collectd_ceilometer.writer import Writer
import logging

log_handler = CollectdLogHandler(collectd=collectd)
logging.getLogger().addHandler(log_handler)
logging.getLogger().setLevel(logging.NOTSET)
LOGGER = logging.getLogger(__name__)


class Plugin(object):
    """Ceilometer plugin with collectd callbacks"""

    # NOTE: this is multithreaded class

    def __init__(self):
        self._meters = None
        self._writer = None
        logging.getLogger("requests").setLevel(logging.WARNING)