Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="node356.html" /> | |
13 | <link rel="prev" href="node354.html" /> | |
14 | <link rel="parent" href="node345.html" /> | |
15 | <link rel="next" href="node356.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.29.5.10 MemoryHandler</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6.29.5.9 SMTPHandler" | |
25 | href="node354.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6.29.5 Handler Objects" | |
28 | href="node345.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.29.5.11 HTTPHandler" | |
31 | href="node356.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="node354.html">6.29.5.9 SMTPHandler</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="node345.html">6.29.5 Handler Objects</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node356.html">6.29.5.11 HTTPHandler</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H3><A NAME="SECTION00829510000000000000000"> | |
56 | 6.29.5.10 MemoryHandler</A> | |
57 | </H3> | |
58 | ||
59 | <P> | |
60 | The <tt class="class">MemoryHandler</tt> supports buffering of logging records in memory, | |
61 | periodically flushing them to a <i class="dfn">target</i> handler. Flushing occurs | |
62 | whenever the buffer is full, or when an event of a certain severity or | |
63 | greater is seen. | |
64 | ||
65 | <P> | |
66 | <tt class="class">MemoryHandler</tt> is a subclass of the more general | |
67 | <tt class="class">BufferingHandler</tt>, which is an abstract class. This buffers logging | |
68 | records in memory. Whenever each record is added to the buffer, a | |
69 | check is made by calling <tt class="method">shouldFlush()</tt> to see if the buffer | |
70 | should be flushed. If it should, then <tt class="method">flush()</tt> is expected to | |
71 | do the needful. | |
72 | ||
73 | <P> | |
74 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
75 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-2544' xml:id='l2h-2544' class="class">BufferingHandler</tt></b>(</nobr></td> | |
76 | <td><var>capacity</var>)</td></tr></table></dt> | |
77 | <dd> | |
78 | Initializes the handler with a buffer of the specified capacity. | |
79 | </dl> | |
80 | ||
81 | <P> | |
82 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
83 | <td><nobr><b><tt id='l2h-2545' xml:id='l2h-2545' class="method">emit</tt></b>(</nobr></td> | |
84 | <td><var>record</var>)</td></tr></table></dt> | |
85 | <dd> | |
86 | Appends the record to the buffer. If <tt class="method">shouldFlush()</tt> returns true, | |
87 | calls <tt class="method">flush()</tt> to process the buffer. | |
88 | </dl> | |
89 | ||
90 | <P> | |
91 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
92 | <td><nobr><b><tt id='l2h-2546' xml:id='l2h-2546' class="method">flush</tt></b>(</nobr></td> | |
93 | <td><var></var>)</td></tr></table></dt> | |
94 | <dd> | |
95 | You can override this to implement custom flushing behavior. This version | |
96 | just zaps the buffer to empty. | |
97 | </dl> | |
98 | ||
99 | <P> | |
100 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
101 | <td><nobr><b><tt id='l2h-2547' xml:id='l2h-2547' class="method">shouldFlush</tt></b>(</nobr></td> | |
102 | <td><var>record</var>)</td></tr></table></dt> | |
103 | <dd> | |
104 | Returns true if the buffer is up to capacity. This method can be | |
105 | overridden to implement custom flushing strategies. | |
106 | </dl> | |
107 | ||
108 | <P> | |
109 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
110 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-2548' xml:id='l2h-2548' class="class">MemoryHandler</tt></b>(</nobr></td> | |
111 | <td><var>capacity</var><big>[</big><var>, flushLevel | |
112 | </var><big>[</big><var>, target</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
113 | <dd> | |
114 | Returns a new instance of the <tt class="class">MemoryHandler</tt> class. The | |
115 | instance is initialized with a buffer size of <var>capacity</var>. If | |
116 | <var>flushLevel</var> is not specified, <tt class="constant">ERROR</tt> is used. If no | |
117 | <var>target</var> is specified, the target will need to be set using | |
118 | <tt class="method">setTarget()</tt> before this handler does anything useful. | |
119 | </dl> | |
120 | ||
121 | <P> | |
122 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
123 | <td><nobr><b><tt id='l2h-2549' xml:id='l2h-2549' class="method">close</tt></b>(</nobr></td> | |
124 | <td><var></var>)</td></tr></table></dt> | |
125 | <dd> | |
126 | Calls <tt class="method">flush()</tt>, sets the target to <tt class="constant">None</tt> and | |
127 | clears the buffer. | |
128 | </dl> | |
129 | ||
130 | <P> | |
131 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
132 | <td><nobr><b><tt id='l2h-2550' xml:id='l2h-2550' class="method">flush</tt></b>(</nobr></td> | |
133 | <td><var></var>)</td></tr></table></dt> | |
134 | <dd> | |
135 | For a <tt class="class">MemoryHandler</tt>, flushing means just sending the buffered | |
136 | records to the target, if there is one. Override if you want | |
137 | different behavior. | |
138 | </dl> | |
139 | ||
140 | <P> | |
141 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
142 | <td><nobr><b><tt id='l2h-2551' xml:id='l2h-2551' class="method">setTarget</tt></b>(</nobr></td> | |
143 | <td><var>target</var>)</td></tr></table></dt> | |
144 | <dd> | |
145 | Sets the target handler for this handler. | |
146 | </dl> | |
147 | ||
148 | <P> | |
149 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
150 | <td><nobr><b><tt id='l2h-2552' xml:id='l2h-2552' class="method">shouldFlush</tt></b>(</nobr></td> | |
151 | <td><var>record</var>)</td></tr></table></dt> | |
152 | <dd> | |
153 | Checks for buffer full or a record at the <var>flushLevel</var> or higher. | |
154 | </dl> | |
155 | ||
156 | <P> | |
157 | ||
158 | <DIV CLASS="navigation"> | |
159 | <div class='online-navigation'> | |
160 | <p></p><hr /> | |
161 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
162 | <tr> | |
163 | <td class='online-navigation'><a rel="prev" title="6.29.5.9 SMTPHandler" | |
164 | href="node354.html"><img src='../icons/previous.png' | |
165 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
166 | <td class='online-navigation'><a rel="parent" title="6.29.5 Handler Objects" | |
167 | href="node345.html"><img src='../icons/up.png' | |
168 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
169 | <td class='online-navigation'><a rel="next" title="6.29.5.11 HTTPHandler" | |
170 | href="node356.html"><img src='../icons/next.png' | |
171 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
172 | <td align="center" width="100%">Python Library Reference</td> | |
173 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
174 | href="contents.html"><img src='../icons/contents.png' | |
175 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
176 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
177 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
178 | <td class='online-navigation'><a rel="index" title="Index" | |
179 | href="genindex.html"><img src='../icons/index.png' | |
180 | border='0' height='32' alt='Index' width='32' /></A></td> | |
181 | </tr></table> | |
182 | <div class='online-navigation'> | |
183 | <b class="navlabel">Previous:</b> | |
184 | <a class="sectref" rel="prev" href="node354.html">6.29.5.9 SMTPHandler</A> | |
185 | <b class="navlabel">Up:</b> | |
186 | <a class="sectref" rel="parent" href="node345.html">6.29.5 Handler Objects</A> | |
187 | <b class="navlabel">Next:</b> | |
188 | <a class="sectref" rel="next" href="node356.html">6.29.5.11 HTTPHandler</A> | |
189 | </div> | |
190 | </div> | |
191 | <hr /> | |
192 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
193 | </DIV> | |
194 | <!--End of Navigation Panel--> | |
195 | <ADDRESS> | |
196 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
197 | </ADDRESS> | |
198 | </BODY> | |
199 | </HTML> |