From dd8c1f1b5eb83ed7038c61ef6cd9fdc50b14777a Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Apr 13 2016 12:57:13 +0000 Subject: Add logging to bugyou_plugins, Update to 0.1.4 --- diff --git a/bugyou_plugins/commands/__init__.py b/bugyou_plugins/commands/__init__.py index e69de29..c7706f1 100644 --- a/bugyou_plugins/commands/__init__.py +++ b/bugyou_plugins/commands/__init__.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2015 Red Hat, Inc. +# +# bugyou_plugins is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# bugyou_plugins is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# bugyou_plugins. If not, see . +# +# Authors: Sayan Chowdhury +# + +from logging.config import dictConfig + +class BaseCommand(object): + def __init__(self): + LOGGING_CONF = dict( + version=1, + formatters=dict( + bare={ + "datefmt": "%Y-%m-%d %H:%M:%S", + "format": "[%(asctime)s][%(name)10s %(levelname)7s] %(message)s" + }, + ), + handlers=dict( + console={ + "class": "logging.StreamHandler", + "formatter": "bare", + "level": "DEBUG", + "stream": "ext://sys.stdout", + } + ), + loggers=dict( + bugyou={ + "level": "DEBUG", + "propagate": False, + "handlers": ["console"], + } + ), + ) + dictConfig(LOGGING_CONF) diff --git a/bugyou_plugins/commands/cntrl.py b/bugyou_plugins/commands/cntrl.py index 4764e3c..39ab7cb 100644 --- a/bugyou_plugins/commands/cntrl.py +++ b/bugyou_plugins/commands/cntrl.py @@ -25,12 +25,16 @@ from retask.queue import Queue from bugyou_plugins.constants import PLUGINS_CONFIG_FILEPATH from bugyou_plugins.utility import load_config +from bugyou_plugins.commands import BaseCommand +import logging +log = logging.getLogger("bugyou") -class PluginController(object): - def __init__(self): - - # Get all the plugins from the config file +class PluginController(BaseCommand): + def __init__(self, *args, **kwargs): + """ Create a list of the Plugins registered in the entry points + """ + super(PluginController, self).__init__(*args, **kwargs) self.config = load_config(PLUGINS_CONFIG_FILEPATH) self.plugins = self.config.sections() @@ -39,20 +43,21 @@ class PluginController(object): plugin_object = entry_point.load() plugin_name = entry_point.name self.active_plugins[plugin_name] = plugin_object + log.info("All Active Plugins Loaded") def notifier(self): - # Connect to the instruction queue and notify bugyou to create a queue - # for the plugin and start pushing the fedmsg messags. - + """ Connect to the instruction queue and notify bugyou to create a queue + for the plugin and start pushing the fedmsg messags. + """ queue = Queue('instruction') queue.connect() for plugin in self.plugins: try: topic = self.config.get(plugin, 'topic') except ConfigParser.NoOptionError: - print 'topic does not exists' + log.error("Config does not exists") if topic is None: - print 'Topic does not exists' + log.info("Config does not exists") continue payload = { diff --git a/bugyou_plugins/plugins/autocloud/plugin.py b/bugyou_plugins/plugins/autocloud/plugin.py index ebf1874..f4eea77 100644 --- a/bugyou_plugins/plugins/autocloud/plugin.py +++ b/bugyou_plugins/plugins/autocloud/plugin.py @@ -20,6 +20,8 @@ from bugyou_plugins.plugins.base import BasePlugin from bugyou_plugins.services.pagure import PagureService +import logging +log = logging.getLogger("bugyou") class AutocloudPlugin(BasePlugin): def __init__(self, *args, **kwargs): @@ -28,6 +30,7 @@ class AutocloudPlugin(BasePlugin): def process(self, msg): for service in self.services: + log.info("Executing Service %s" % service.SERVICE) getattr(self, 'do_%s'%service.SERVICE)(msg) def _get_issues_title(self, issues): @@ -36,6 +39,7 @@ class AutocloudPlugin(BasePlugin): return {issue['title'] for issue in issues} def do_pagure(self, msg): + log.info("Received message %s" % msg['body']['msg_id']) pagure_obj = PagureService(plugin_name=self.plugin_name) issue_content_templ = """ @@ -70,10 +74,12 @@ class AutocloudPlugin(BasePlugin): matched_issue = (issue for issue in issues if issue['title'] == lookup_key).next() issue_id = matched_issue['id'] + log.info("Updating issue %s:%s" % (self.plugin_name, issue_id)) pagure_obj.update_issue(issue_id=issue_id, content=content) elif 'failed' in topic: + log.info("Creating issue %s" % self.plugin_name) pagure_obj.create_issue(title=lookup_key, content=content) if 'success' in topic: @@ -82,4 +88,5 @@ class AutocloudPlugin(BasePlugin): if issue['title'] == lookup_key).next() issue_id = matched_issue['id'] + log.info("Closing issue %s:%s" % (self.plugin_name, issue_id)) pagure_obj.close_issue(issue_id=issue_id) diff --git a/bugyou_plugins/plugins/base.py b/bugyou_plugins/plugins/base.py index 2b5d798..7f82107 100644 --- a/bugyou_plugins/plugins/base.py +++ b/bugyou_plugins/plugins/base.py @@ -26,6 +26,8 @@ from retask.queue import Queue from bugyou_plugins.constants import PLUGINS_CONFIG_FILEPATH from bugyou_plugins.utility import get_active_services, load_config +import logging +log = logging.getLogger("bugyou") class BasePlugin(object): __metaclass__ = abc.ABCMeta @@ -44,15 +46,16 @@ class BasePlugin(object): """ Connect to the retask queue for the plugin """ self.queue = Queue(self.plugin_name) conn = self.queue.connect() - print 'Init retask connection' + log.info("Initializing redis conection: %s" % self.plugin_name) if not conn: - print 'Could not connect to %s queue' % self.plugin_name + log.error("Could not connect to %s queue" % self.plugin_name) return False def consume(self): while True: task = self.queue.wait() if task: + log.debug("Processing Message: %s" % task.data['msg']['body']['msg_id']) self.process(task.data['msg']) def init_worker(self): @@ -63,10 +66,10 @@ class BasePlugin(object): def load_services(self): """ Load the services for the plugin """ services = self.config.get(self.plugin_name, 'services').split(',') + log.info("Start loading services") for service in services: - print 'Load', service self.services.append(self.active_services[service].load()) - print self.services + log.info("Complete loading services %s" % self.services) @abc.abstractmethod def process(self): diff --git a/setup.py b/setup.py index 7d2c584..3afa9d6 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ requires = [] setup( name='bugyou_plugins', - version='0.1.3', + version='0.1.4', description='Plugins for bugyou, an automatic bug reporting tool', author='Sayan Chowdhury', author_email='sayanchowdhury@fedoraproject.org',