logging.SocketHandler connections

oj ojeeves at gmail.com
Thu Nov 15 16:23:36 CET 2007

Hi folks,

I'm writing some fairly simple logging code that makes use of the

The example server code works fine, as expected. (http://

However, initially, I had tried it with a server that closed the
connection after receiving each record, and the SocketHandler doesn't
seem to behave as advertised.

My test script was simply this:


import logging
import logging.handlers
import time
import sys

port = 12345

handler = logging.handlers.SocketHandler('localhost', port)
l = logging.getLogger("my-logger")

for i in xrange(10):
	l.info("Log message %i", i)

My test server received messages 0, 3, 6 and 9.

Doing a packet capture with wireshark confirmed that it only made 4

The SocketHandler documentation says that it will re-establish the
connection if it has been closed. After a bit of digging, I found a
patch had been submitted and accepted that made it back off
exponentially. However, this should be time based. Even if I make my
sleep here 30 seconds, my server still only receives messages 0, 3, 6
and 9.

I'm concerned that if a connection is lost at some point, I will
always lose at least 2 log messages.

Is there some reason for this that I am not aware of? Have I
misunderstood something, or is this a bug?


More information about the Python-list mailing list