Last active
September 8, 2017 20:10
Revisions
-
tylerpace revised this gist
Sep 8, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ import json import logging import requests class HipChatHandler(logging.Handler): -
tylerpace revised this gist
Sep 8, 2017 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,9 @@ import json import logging import requests from requests.auth import HTTPBasicAuth class HipChatHandler(logging.Handler): def __init__(self, auth_token, room_id, level=logging.INFO): -
tylerpace renamed this gist
Sep 8, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
tylerpace created this gist
Sep 8, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ class HipChatHandler(logging.Handler): def __init__(self, auth_token, room_id, level=logging.INFO): super(self.__class__, self).__init__(level) self.api_uri = 'https://api.hipchat.com/v2/room/{room}/notification?auth_token={auth}' self.auth_token = auth_token self.room_id = room_id self.options = { logging.CRITICAL: {'color': 'red', 'notify': True}, logging.ERROR: {'color': 'red', 'notify': True}, logging.WARNING: {'color': 'yellow', 'notify': True}, logging.INFO: {'color': 'gray', 'notify': False}, logging.DEBUG: {'color': 'gray', 'notify': False}, logging.NOTSET: {'color': 'gray', 'notify': False} } def emit(self, record): try: body = record.__dict__ data = { 'message': self.format(record), 'message_format': 'text', 'color': self.options[body['levelno']]['color'], 'notify': self.options[body['levelno']]['notify'], } uri = self.api_uri.format(room=self.room_id, auth=self.auth_token) requests.post(uri, data=json.dumps(data), headers={'content-type': 'application/json'}) except: # pylint: disable=W0702 self.handleError(record)