IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
14.5.5.10 MemoryHandler

14.5.5.10 MemoryHandler

The MemoryHandler class, located in the logging.handlers module, supports buffering of logging records in memory, periodically flushing them to a target handler. Flushing occurs whenever the buffer is full, or when an event of a certain severity or greater is seen.

MemoryHandler is a subclass of the more general BufferingHandler, which is an abstract class. This buffers logging records in memory. Whenever each record is added to the buffer, a check is made by calling shouldFlush() to see if the buffer should be flushed. If it should, then flush() is expected to do the needful.

class BufferingHandler( capacity)
Initializes the handler with a buffer of the specified capacity.

emit( record)
Appends the record to the buffer. If shouldFlush() returns true, calls flush() to process the buffer.

flush( )
You can override this to implement custom flushing behavior. This version just zaps the buffer to empty.

shouldFlush( record)
Returns true if the buffer is up to capacity. This method can be overridden to implement custom flushing strategies.

class MemoryHandler( capacity[, flushLevel [, target]])
Returns a new instance of the MemoryHandler class. The instance is initialized with a buffer size of capacity. If flushLevel is not specified, ERROR is used. If no target is specified, the target will need to be set using setTarget() before this handler does anything useful.

close( )
Calls flush(), sets the target to None and clears the buffer.

flush( )
For a MemoryHandler, flushing means just sending the buffered records to the target, if there is one. Override if you want different behavior.

setTarget( target)
Sets the target handler for this handler.

shouldFlush( record)
Checks for buffer full or a record at the flushLevel or higher.

See About this document... for information on suggesting changes.