36
36
from canonical.librarian.utils import copy_and_close
39
class OOPSLoggingObserver(log.PythonLoggingObserver):
40
"""A version of `PythonLoggingObserver` that logs OOPSes for errors."""
41
# XXX: JonathanLange 2008-12-23 bug=314959: As best as I can tell, this
42
# ought to be a log *handler*, not a feature of the bridge from
43
# Twisted->Python logging. Ask Michael about this.
45
def emit(self, eventDict):
46
"""See `PythonLoggingObserver.emit`."""
47
if eventDict.get('isError', False) and 'failure' in eventDict:
49
failure = eventDict['failure']
50
request = log_oops_from_failure(failure)
52
"Logged OOPS id %s: %s: %s",
53
request.oopsid, failure.type.__name__, failure.value)
55
self.logger.exception("Error reporting OOPS:")
57
log.PythonLoggingObserver.emit(self, eventDict)
60
def log_oops_from_failure(failure, URL=None, **args):
61
request = errorlog.ScriptRequest(args.items(), URL=URL)
62
errorlog.globalErrorUtility.raising(
63
(failure.type, failure.value, failure.getTraceback()),
68
39
def set_up_logging_for_script(options, name):
69
40
"""Create a `Logger` object and configure twisted to use it.
97
def set_up_oops_reporting(configuration, name, mangle_stdout=True):
68
def set_up_oops_reporting(name, configuration, mangle_stdout=True):
98
69
"""Set up OOPS reporting by starting the Twisted logger with an observer.
71
:param name: The name of the logger to use for oops reporting.
100
72
:param configuration: The name of the config section to use for oops
102
:param name: The name of the logger to use for oops reporting.
103
74
:param mangle_stdout: If True, send stdout and stderr to the logger.
104
75
Defaults to False.
106
errorlog.globalErrorUtility.configure(configuration)
107
log.startLoggingWithObserver(
108
OOPSLoggingObserver(loggerName=name).emit, mangle_stdout)
77
errorlog.globalErrorUtility.configure(
79
config_factory=oops_twisted.Config,
80
publisher_adapter=oops_twisted.defer_publisher)
81
oops_observer = OOPSObserver(errorlog.globalErrorUtility._oops_config,
82
log.PythonLoggingObserver(loggerName=name).emit)
83
log.startLoggingWithObserver(oops_observer.emit, mangle_stdout)
111
86
class LaunchpadLogFile(DailyLogFile):