Improved pastebin logs to search via regex and timestamps for error line then grab 50 lines of data before that.

This commit is contained in:
echel0n 2014-12-19 13:24:41 -08:00
parent 120ea961f2
commit 477938e5f3
2 changed files with 20 additions and 8 deletions

View File

@ -18,6 +18,7 @@
from __future__ import with_statement
import os
import re
import sys
import logging
import logging.handlers
@ -25,8 +26,7 @@ import threading
import platform
import sickbeard
from sickbeard import classes
from sickbeard.encodingKludge import ek
from sickbeard import classes, encodingKludge as ek
from github import Github
from pastebin import PastebinAPI
@ -147,13 +147,10 @@ class Logger(object):
self.gh_issues = Github(login_or_token=sickbeard.GIT_USERNAME, password=sickbeard.GIT_PASSWORD,
user_agent="SiCKRAGE").get_organization(gh_org).get_repo(gh_repo)
pastebin_url = None
try:
if self.logFile and os.path.isfile(self.logFile):
with ek(open, self.logFile) as f:
data = f.readlines()
data = "".join(data[len(data) - 100:])
pastebin_url = PastebinAPI().paste('f59b8e9fa1fc2d033e399e6c7fb09d19', data)
with ek.ek(open, self.logFile) as f:
log_data = f.readlines()
except Exception as e:
pass
@ -162,6 +159,19 @@ class Logger(object):
if not curError.title:
continue
regex = "^(%s)\s*([A-Z]+)\s*(.+?)\s*\:\:\s*(.*)$" % curError.time
pastebin_url = None
for i, x in enumerate(reversed(log_data)):
x = ek.ss(x)
match = re.match(regex, x)
if match:
level = match.group(2)
if reverseNames[level] >= ERROR:
paste_data = "".join(log_data[len(log_data) - i - 50:])
pastebin_url = PastebinAPI().paste('f59b8e9fa1fc2d033e399e6c7fb09d19', paste_data)
break
message = u"### INFO\n"
message += u"Python Version: **" + sys.version[:120] + "**\n"
message += u"Operating System: **" + platform.platform() + "**\n"

View File

@ -231,7 +231,8 @@ class WebHandler(BaseHandler):
callback(result)
return result
except:
logger.log('Failed doing webui callback: %s' % (traceback.format_exc()), logger.DEBUG)
logger.log('Failed doing webui callback: %s' % (traceback.format_exc()), logger.ERROR)
raise
def async_done(self, results):
try:
@ -241,6 +242,7 @@ class WebHandler(BaseHandler):
logger.log('Failed sending webui reponse: %s' % (traceback.format_exc()), logger.DEBUG)
raise
# post uses get method
post = get