[Twisted-Python] How to best log server/client interactions from a test?
glyph at twistedmatrix.com
Fri Jul 13 18:21:33 EDT 2012
On Jul 12, 2012, at 1:31 PM, Dan Milstein <dan at wingu.com> wrote:
> 'lo all,
> I've been doing some work with the twisted.mail.imap4 module, and its associated unit tests (in order to learn the code more, I'm tackling a few of the outstanding tickets).
> When running those tests, I'd often like to log all the server/client interaction. I managed to do so by way of hacking the code in twisted.protocols.loopback, but that feels pretty wrong. What's a good way to get all the interaction logged?
> To be more specific, the tests in question (e.g. test_imap.NewFetchTestCase), do a lot of:
> d = loopback.loopbackTCP(self.server, self.client, noisy=False)
> d.addCallback(lambda x : self.assertEqual(self.result, self.expected))
> return d
> What's a Good Way to get all the traffic going over that loopback logged? Setting noisy to True merely gets it to log some protocol startup/teardown-type messages.
> Or: given that I've figured out how to hack loopback.lookupbackTCP, if there's general utility, I can certainly add a keyword arg to trigger logging of all messages, e.g. logAll=False (I'm trying to find something which feels meaningfully different from 'noisy', because it would seem Very Wrong Indeed to make noisy suddenly produce vastly more log output). Is that something people might be interested in?
If you're interested in logging at the TCP connection level, have you considered moving this out of your Twisted process entirely and using some tool like Wireshark? You could build something yourself by interposing transport objects that dump their data, but you'd have to build your own toolchain (command line tools, GUIs, etc) for actually examining the output, whereas existing protocol analysis tools would just do that for you.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python