Kiln » Kiln Storage Service Read More
Clone URL:  
bugzscout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os import settings LOG_NAME = 'bugzscout' class BugzScout(object): def __init__(self, parent=None): import logging if parent: self.logger = logging.getLogger('%s.%s' % (parent, LOG_NAME)) else: self.logger = logging.getLogger(LOG_NAME) if not self.logger.handlers: try: self.logger.addHandler(logging.FileHandler(filename=os.path.join(settings.KILN_REPOSITORY_ROOT, 'errors.txt'))) except IOError, e: # Can't open that file. try: # Try putting one in the current directory. self.logger.addHandler(logging.FileHandler(filename='errors.txt')) self.logger.error(e) except IOError, e: # OK, files aren't an option. Go to stderr. self.logger.addHandler(logging.StreamHandler()) self.logger.error(e) def report_exception(self, e, extra='', project='Kiln', area='Backend'): def get_stack_trace(): import traceback, sys return '\n'.join(traceback.format_exception(*sys.exc_info())) if extra: extra += '\n\n' extra += get_stack_trace() self.report_error(str(e), extra, project, area) def report_error(self, error_msg, extra='', project='Kiln', area='Backend'): from socket import gethostname if extra: extra = 'Host: %s\n\n%s' % (gethostname(), extra) description = str(error_msg) bug = {'ScoutUserName': 'BugzScout', 'ScoutProject': project, 'ScoutArea': area, 'Description': description, 'Extra': extra} self.logger.error(description) if extra: self.logger.error('Extra info:\n%s', extra) if settings.HOSTED: self.send_bug(bug) def send_bug(self, bug): import urllib, urllib2 try: urllib2.urlopen('http://our.fogbugz.com/scoutSubmit.asp', urllib.urlencode(bug)) except Exception, e: self.logger.critical('Error reporting bug to BugzScout\n%s', bug) self.logger.critical('Exception: %s', e) def report_exception(*args, **kwargs): return BugzScout().report_exception(*args, **kwargs) def report_error(*args, **kwargs): return BugzScout().report_error(*args, **kwargs)