import os, threading, logging, logging.handlers class LoggerThread(threading.Thread): def __init__(self, numLoops): threading.Thread.__init__(self) self.numLoops = numLoops def run(self): for x in range(0, self.numLoops): os.system('cd.>blah.txt') os.system('del blah.txt') logging.debug('This is log message ' + str(x) + ' from ' + self.name + ' and I think this should be a little longer, so I\'ll add some more data here because perhaps the size of the individual log message is a factor. Who knows for sure until this simple test fails.') if __name__=="__main__": logSize = 2048 numberOfLogs = 10 files = logging.handlers.RotatingFileHandler('logthred.log', 'a', logSize, numberOfLogs) console = logging.StreamHandler() # set a format fileFormatter = logging.Formatter('%(asctime)s %(levelname)-8s %(thread)-4s %(message)s') consoleFormatter = logging.Formatter('%(asctime)s %(levelname)-8s %(thread)-4s %(message)s') # tell the handler to use this format files.setFormatter(fileFormatter) console.setFormatter(consoleFormatter) # add the handlers to the root logger logging.getLogger('').addHandler(files) logging.getLogger('').addHandler(console) logging.getLogger('').setLevel(logging.DEBUG) numThreads = 10 numLoops = 100 # Create and execute threads for x in range(0, numThreads): LoggerThread(numLoops).start()