<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"node356.html" />
<link rel=
"prev" href=
"node354.html" />
<link rel=
"parent" href=
"node345.html" />
<link rel=
"next" href=
"node356.html" />
<meta name='aesop' content='information'
/>
<title>6.29.5.10 MemoryHandler
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.29.5.9 SMTPHandler"
href=
"node354.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6.29.5 Handler Objects"
href=
"node345.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.29.5.11 HTTPHandler"
href=
"node356.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"node354.html">6.29.5.9 SMTPHandler
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"node345.html">6.29.5 Handler Objects
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"node356.html">6.29.5.11 HTTPHandler
</A>
<!--End of Navigation Panel-->
<H3><A NAME=
"SECTION00829510000000000000000">
6.29.5.10 MemoryHandler
</A>
The
<tt class=
"class">MemoryHandler
</tt> supports buffering of logging records in memory,
periodically flushing them to a
<i class=
"dfn">target
</i> handler. Flushing occurs
whenever the buffer is full, or when an event of a certain severity or
<tt class=
"class">MemoryHandler
</tt> is a subclass of the more general
<tt class=
"class">BufferingHandler
</tt>, 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
<tt class=
"method">shouldFlush()
</tt> to see if the buffer
should be flushed. If it should, then
<tt class=
"method">flush()
</tt> is expected to
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
2544' xml:id='l2h-
2544'
class=
"class">BufferingHandler
</tt></b>(
</nobr></td>
<td><var>capacity
</var>)
</td></tr></table></dt>
Initializes the handler with a buffer of the specified capacity.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2545' xml:id='l2h-
2545'
class=
"method">emit
</tt></b>(
</nobr></td>
<td><var>record
</var>)
</td></tr></table></dt>
Appends the record to the buffer. If
<tt class=
"method">shouldFlush()
</tt> returns true,
calls
<tt class=
"method">flush()
</tt> to process the buffer.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2546' xml:id='l2h-
2546'
class=
"method">flush
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
You can override this to implement custom flushing behavior. This version
just zaps the buffer to empty.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2547' xml:id='l2h-
2547'
class=
"method">shouldFlush
</tt></b>(
</nobr></td>
<td><var>record
</var>)
</td></tr></table></dt>
Returns true if the buffer is up to capacity. This method can be
overridden to implement custom flushing strategies.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
2548' xml:id='l2h-
2548'
class=
"class">MemoryHandler
</tt></b>(
</nobr></td>
<td><var>capacity
</var><big>[
</big><var>, flushLevel
</var><big>[
</big><var>, target
</var><big>]
</big><var></var><big>]
</big><var></var>)
</td></tr></table></dt>
Returns a new instance of the
<tt class=
"class">MemoryHandler
</tt> class. The
instance is initialized with a buffer size of
<var>capacity
</var>. If
<var>flushLevel
</var> is not specified,
<tt class=
"constant">ERROR
</tt> is used. If no
<var>target
</var> is specified, the target will need to be set using
<tt class=
"method">setTarget()
</tt> before this handler does anything useful.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2549' xml:id='l2h-
2549'
class=
"method">close
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Calls
<tt class=
"method">flush()
</tt>, sets the target to
<tt class=
"constant">None
</tt> and
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2550' xml:id='l2h-
2550'
class=
"method">flush
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
For a
<tt class=
"class">MemoryHandler
</tt>, flushing means just sending the buffered
records to the target, if there is one. Override if you want
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2551' xml:id='l2h-
2551'
class=
"method">setTarget
</tt></b>(
</nobr></td>
<td><var>target
</var>)
</td></tr></table></dt>
Sets the target handler for this handler.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2552' xml:id='l2h-
2552'
class=
"method">shouldFlush
</tt></b>(
</nobr></td>
<td><var>record
</var>)
</td></tr></table></dt>
Checks for buffer full or a record at the
<var>flushLevel
</var> or higher.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.29.5.9 SMTPHandler"
href=
"node354.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6.29.5 Handler Objects"
href=
"node345.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.29.5.11 HTTPHandler"
href=
"node356.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"node354.html">6.29.5.9 SMTPHandler
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"node345.html">6.29.5 Handler Objects
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"node356.html">6.29.5.11 HTTPHandler
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.