From 22c2c3a408dd1af644b1c58863cac9601de75866 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 23 Aug 2004 23:16:29 +0000 Subject: [PATCH] Let's make ourselves able to trace to a file. --- sandbox/Debug.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sandbox/Debug.py b/sandbox/Debug.py index 19fc91edc..280214a1a 100644 --- a/sandbox/Debug.py +++ b/sandbox/Debug.py @@ -53,9 +53,12 @@ def configure(advanced): from questions import expect, anything, something, yn conf.registerPlugin('Debug', True) -def tracer(frame, event, _): - if event == 'call': - print '%s: %s' % (frame.f_code.co_filename, frame.f_code.co_name) +def getTracer(fd): + def tracer(frame, event, _): + if event == 'call': + code = frame.f_code + print >>fd, '%s: %s' % (code.co_filename, code.co_name) + return tracer class Debug(privmsgs.CapabilityCheckingPrivmsg): @@ -89,11 +92,17 @@ class Debug(privmsgs.CapabilityCheckingPrivmsg): irc.sendMsg(msg) def settrace(self, irc, msg, args): - """takes no arguments + """[] - Starts tracing function calls on stdout. This causes much output. + Starts tracing function calls to . If is not + given, sys.stdout is used. This causes much output. """ - sys.settrace(tracer) + filename = privmsgs.getArgs(args, optional=1, required=0) + if filename: + fd = file(filename, 'a') + else: + fd = sys.stdout + sys.settrace(getTracer(fd)) irc.replySuccess() def unsettrace(self, irc, msg, args):