42
42
This also configures oops reporting to use the section named
44
44
logger_object = logger(options, name)
45
set_up_oops_reporting(name, name, mangle_stdout=True)
45
observer = set_up_oops_reporting(name, name)
46
log.startLoggingWithObserver(observer)
46
47
return logger_object
49
def set_up_tacfile_logging(name, level):
50
"""Create a `Logger` object for use in tac files.
52
This is preferable to use over `set_up_logging_for_script` for .tac
53
files since there's no options to pass through. The logger object
54
is connected to Twisted's log and returned.
56
:param name: The logger instance name.
57
:param level: The log level to use, eg. logging.INFO or logging.DEBUG
59
logger = logging.getLogger(name)
60
channel = logging.StreamHandler(log.StdioOnnaStick())
61
channel.setLevel(level)
62
channel.setFormatter(logging.Formatter('%(message)s'))
63
logger.addHandler(channel)
64
logger.setLevel(level)
68
def set_up_oops_reporting(name, configuration, mangle_stdout=True):
50
def set_up_oops_reporting(name, configuration, logfile):
69
51
"""Set up OOPS reporting by starting the Twisted logger with an observer.
71
53
:param name: The name of the logger to use for oops reporting.
72
54
:param configuration: The name of the config section to use for oops
74
:param mangle_stdout: If True, send stdout and stderr to the logger.
56
:param logfile: File to log output to.
77
58
errorlog.globalErrorUtility.configure(
79
60
config_factory=oops_twisted.Config,
80
61
publisher_adapter=oops_twisted.defer_publisher)
62
log_observer = RotatableFileLogObserver(logfile)
81
63
oops_observer = OOPSObserver(errorlog.globalErrorUtility._oops_config,
82
log.PythonLoggingObserver(loggerName=name).emit)
83
log.startLoggingWithObserver(oops_observer.emit, mangle_stdout)
86
68
class LaunchpadLogFile(DailyLogFile):