Daniel Watkins 523967580a Refactor handlers out of main reporting module.
This will give us a clearer separation between the core reporting code
(which shouldn't change very often) and the handler code (which is
likely to change more often as we add new handlers and new features to
existing handlers).

It is also the first (baby) step on the path of making handlers
pluggable so third-parties can easily drop their own in.

Change-Id: I648df057d2ff719a2a81398afc80aaef9225ff5c
2015-07-31 17:13:46 +01:00

26 lines
654 B
Python

import abc
import logging
from cloudinit.registry import DictRegistry
class ReportingHandler(object):
@abc.abstractmethod
def publish_event(self, event):
raise NotImplementedError
class LogHandler(ReportingHandler):
"""Publishes events to the cloud-init log at the ``INFO`` log level."""
def publish_event(self, event):
"""Publish an event to the ``INFO`` log level."""
logger = logging.getLogger(
'.'.join(['cloudinit', 'reporting', event.event_type, event.name]))
logger.info(event.as_string())
available_handlers = DictRegistry()
available_handlers.register_item('log', LogHandler)