Skip to content

Commit

Permalink
Added logger on listener output instead of returns
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaume Florez committed Nov 9, 2016
1 parent ff11d51 commit d300a96
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hookshub/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import tempfile
import shutil
import logging


class TempDir(object):
Expand Down Expand Up @@ -38,6 +39,7 @@ def instancer(payload):
return github(payload)

def run_event_actions(self, config_file):
logger = logging.getLogger('__main__')
def_conf = {}

with open(config_file, 'r') as config:
Expand All @@ -52,11 +54,11 @@ def run_event_actions(self, config_file):

hook = self.instancer(self.payload)
i = 0
log = 'Executed {} actions\n'.format(len(hook.event_actions))
logger.info('Executing {} actions\n'.format(len(hook.event_actions)))

for action in hook.event_actions:
i += 1
log += ('[Running: <{0}/{1}> - {2}]\n'.format(
logger.info('[Running: <{0}/{1}> - {2}]\n'.format(
i, len(hook.event_actions), action)
)
args = hook.get_exe_action(action, conf)
Expand All @@ -75,11 +77,13 @@ def run_event_actions(self, config_file):
action, stderr
))
if proc.returncode != 0:
log += ('[{0}]:{1}\n[{0}]:Failed!\n'.format(
log = ('[{0}]:{1}\n[{0}]:Failed!\n'.format(
action, output
))
logger.error(log.replace('|', '\n'))
return -1, log
log += ('[{0}]:{1}\n[{0}]:Success!\n'.format(
log = ('[{0}]:{1}\n[{0}]:Success!\n'.format(
action, output
))
logger.info(log.replace('|', '\n'))
return 0, log

0 comments on commit d300a96

Please sign in to comment.