When I write a log to file using the standard module logging, will each log be flushed to disk separately? For example, will the following code flush log by 10 times?
logging.basicConfig(level=logging.DEBUG, filename='debug.log')
for i in xrange(10):
logging.debug("test")
if so, will it slow down ?
Yes, it does flush the output at every call. You can see this in the source code for the
StreamHandler
:I wouldn't really mind about the performance of logging, at least not before profiling and discovering that it is a bottleneck. Anyway you can always create a
Handler
subclass that doesn't performflush
at every call toemit
(even though you will risk to lose a lot of logs if a bad exception occurs/the interpreter crashes).