performance - Does python logging flush every log? -
when write log file using standard module logging, each log flushed disk separately? example, following code flush log 10 times?
logging.basicconfig(level=logging.debug, filename='debug.log') in xrange(10): logging.debug("test")
if so, slow down ?
yes, flush output @ every call. can see in source code streamhandler
:
def flush(self): """ flushes stream. """ self.acquire() try: if self.stream , hasattr(self.stream, "flush"): self.stream.flush() finally: self.release() def emit(self, record): """ emit record. if formatter specified, used format record. record written stream trailing newline. if exception information present, formatted using traceback.print_exception , appended stream. if stream has 'encoding' attribute, used determine how output stream. """ try: msg = self.format(record) stream = self.stream stream.write(msg) stream.write(self.terminator) self.flush() # <--- except (keyboardinterrupt, systemexit): #pragma: no cover raise except: self.handleerror(record)
i wouldn't mind performance of logging, @ least not before profiling , discovering bottleneck. anyway can create handler
subclass doesn't perform flush
@ every call emit
(even though risk lose lot of logs if bad exception occurs/the interpreter crashes).
Comments
Post a Comment