summaryrefslogtreecommitdiff
path: root/cloudinit/reporting/handlers.py
blob: 1d5ca524cb44d11db5f61a2969817da3aced0440 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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())


class StderrHandler(ReportingHandler):
    def publish_event(self, event):
        #sys.stderr.write(event.as_string() + "\n")
        print(event.as_string())


available_handlers = DictRegistry()
available_handlers.register_item('log', LogHandler)
available_handlers.register_item('print', StderrHandler)