1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2025-05-11 11:19:48 +00:00

cocoalib: Replaced the "Relevant Console log" mechanism

The old grepping method wasn't reliable and now, we simply keep the last
20 logs in memory to place in that section of error reporting.
This commit is contained in:
Virgil Dupras 2014-03-15 13:57:34 -04:00
parent d924d7797a
commit a29e007475

View File

@ -9,7 +9,6 @@
import logging import logging
import time import time
import traceback import traceback
import subprocess
import sys import sys
from hscommon.error_report import send_error_report from hscommon.error_report import send_error_report
@ -90,23 +89,24 @@ def report_crash(type, value, tb):
s += "Application Version: {}\n".format(app_version) s += "Application Version: {}\n".format(app_version)
s += "Mac OS X Version: {}\n\n".format(osx_version) s += "Mac OS X Version: {}\n\n".format(osx_version)
s += ''.join(safe_format_exception(type, value, tb)) s += ''.join(safe_format_exception(type, value, tb))
if app_identifier: if LOG_BUFFER:
s += '\nRelevant Console logs:\n\n' s += '\nRelevant Console logs:\n\n'
p = subprocess.Popen(['grep', app_identifier, '/var/log/system.log'], stdout=subprocess.PIPE) s += '\n'.join(LOG_BUFFER)
try:
s += str(p.communicate()[0], encoding='utf-8')
except IndexError:
# This can happen if something went wrong with the grep (permission errors?)
pass
if proxy.reportCrash_(s): if proxy.reportCrash_(s):
send_error_report(s) send_error_report(s)
def install_exception_hook(): def install_exception_hook():
sys.excepthook = report_crash sys.excepthook = report_crash
# A global log buffer to use for error reports
LOG_BUFFER = []
class CocoaHandler(logging.Handler): class CocoaHandler(logging.Handler):
def emit(self, record): def emit(self, record):
proxy.log_(record.getMessage()) msg = record.getMessage()
proxy.log_(msg)
LOG_BUFFER.append(msg)
del LOG_BUFFER[:-20]
def install_cocoa_logger(): def install_cocoa_logger():
logging.getLogger().addHandler(CocoaHandler()) logging.getLogger().addHandler(CocoaHandler())