Commit | Line | Data |
---|---|---|
86530b38 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="node357.html" /> | |
13 | <link rel="prev" href="network-logging.html" /> | |
14 | <link rel="parent" href="module-logging.html" /> | |
15 | <link rel="next" href="node346.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.29.5 Handler Objects</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.4 Sending and receiving" | |
25 | href="network-logging.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 logging " | |
28 | href="module-logging.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.1 StreamHandler" | |
31 | href="node346.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="network-logging.html">6.29.4 Sending and receiving</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-logging.html">6.29 logging </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node346.html">6.29.5.1 StreamHandler</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION0082950000000000000000"> | |
56 | 6.29.5 Handler Objects</A> | |
57 | </H2> | |
58 | ||
59 | <P> | |
60 | Handlers have the following attributes and methods. Note that | |
61 | <tt class="class">Handler</tt> is never instantiated directly; this class acts as a | |
62 | base for more useful subclasses. However, the <tt class="method">__init__()</tt> | |
63 | method in subclasses needs to call <tt class="method">Handler.__init__()</tt>. | |
64 | ||
65 | <P> | |
66 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
67 | <td><nobr><b><tt id='l2h-2492' xml:id='l2h-2492' class="method">__init__</tt></b>(</nobr></td> | |
68 | <td><var>level=<tt class="constant">NOTSET</tt></var>)</td></tr></table></dt> | |
69 | <dd> | |
70 | Initializes the <tt class="class">Handler</tt> instance by setting its level, setting | |
71 | the list of filters to the empty list and creating a lock (using | |
72 | <tt class="method">createLock()</tt>) for serializing access to an I/O mechanism. | |
73 | </dl> | |
74 | ||
75 | <P> | |
76 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
77 | <td><nobr><b><tt id='l2h-2493' xml:id='l2h-2493' class="method">createLock</tt></b>(</nobr></td> | |
78 | <td><var></var>)</td></tr></table></dt> | |
79 | <dd> | |
80 | Initializes a thread lock which can be used to serialize access to | |
81 | underlying I/O functionality which may not be threadsafe. | |
82 | </dl> | |
83 | ||
84 | <P> | |
85 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
86 | <td><nobr><b><tt id='l2h-2494' xml:id='l2h-2494' class="method">acquire</tt></b>(</nobr></td> | |
87 | <td><var></var>)</td></tr></table></dt> | |
88 | <dd> | |
89 | Acquires the thread lock created with <tt class="method">createLock()</tt>. | |
90 | </dl> | |
91 | ||
92 | <P> | |
93 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
94 | <td><nobr><b><tt id='l2h-2495' xml:id='l2h-2495' class="method">release</tt></b>(</nobr></td> | |
95 | <td><var></var>)</td></tr></table></dt> | |
96 | <dd> | |
97 | Releases the thread lock acquired with <tt class="method">acquire()</tt>. | |
98 | </dl> | |
99 | ||
100 | <P> | |
101 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
102 | <td><nobr><b><tt id='l2h-2496' xml:id='l2h-2496' class="method">setLevel</tt></b>(</nobr></td> | |
103 | <td><var>lvl</var>)</td></tr></table></dt> | |
104 | <dd> | |
105 | Sets the threshold for this handler to <var>lvl</var>. Logging messages which are | |
106 | less severe than <var>lvl</var> will be ignored. When a handler is created, the | |
107 | level is set to <tt class="constant">NOTSET</tt> (which causes all messages to be processed). | |
108 | </dl> | |
109 | ||
110 | <P> | |
111 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
112 | <td><nobr><b><tt id='l2h-2497' xml:id='l2h-2497' class="method">setFormatter</tt></b>(</nobr></td> | |
113 | <td><var>form</var>)</td></tr></table></dt> | |
114 | <dd> | |
115 | Sets the <tt class="class">Formatter</tt> for this handler to <var>form</var>. | |
116 | </dl> | |
117 | ||
118 | <P> | |
119 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
120 | <td><nobr><b><tt id='l2h-2498' xml:id='l2h-2498' class="method">addFilter</tt></b>(</nobr></td> | |
121 | <td><var>filt</var>)</td></tr></table></dt> | |
122 | <dd> | |
123 | Adds the specified filter <var>filt</var> to this handler. | |
124 | </dl> | |
125 | ||
126 | <P> | |
127 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
128 | <td><nobr><b><tt id='l2h-2499' xml:id='l2h-2499' class="method">removeFilter</tt></b>(</nobr></td> | |
129 | <td><var>filt</var>)</td></tr></table></dt> | |
130 | <dd> | |
131 | Removes the specified filter <var>filt</var> from this handler. | |
132 | </dl> | |
133 | ||
134 | <P> | |
135 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
136 | <td><nobr><b><tt id='l2h-2500' xml:id='l2h-2500' class="method">filter</tt></b>(</nobr></td> | |
137 | <td><var>record</var>)</td></tr></table></dt> | |
138 | <dd> | |
139 | Applies this handler's filters to the record and returns a true value if | |
140 | the record is to be processed. | |
141 | </dl> | |
142 | ||
143 | <P> | |
144 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
145 | <td><nobr><b><tt id='l2h-2501' xml:id='l2h-2501' class="method">flush</tt></b>(</nobr></td> | |
146 | <td><var></var>)</td></tr></table></dt> | |
147 | <dd> | |
148 | Ensure all logging output has been flushed. This version does | |
149 | nothing and is intended to be implemented by subclasses. | |
150 | </dl> | |
151 | ||
152 | <P> | |
153 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
154 | <td><nobr><b><tt id='l2h-2502' xml:id='l2h-2502' class="method">close</tt></b>(</nobr></td> | |
155 | <td><var></var>)</td></tr></table></dt> | |
156 | <dd> | |
157 | Tidy up any resources used by the handler. This version does | |
158 | nothing and is intended to be implemented by subclasses. | |
159 | </dl> | |
160 | ||
161 | <P> | |
162 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
163 | <td><nobr><b><tt id='l2h-2503' xml:id='l2h-2503' class="method">handle</tt></b>(</nobr></td> | |
164 | <td><var>record</var>)</td></tr></table></dt> | |
165 | <dd> | |
166 | Conditionally emits the specified logging record, depending on | |
167 | filters which may have been added to the handler. Wraps the actual | |
168 | emission of the record with acquisition/release of the I/O thread | |
169 | lock. | |
170 | </dl> | |
171 | ||
172 | <P> | |
173 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
174 | <td><nobr><b><tt id='l2h-2504' xml:id='l2h-2504' class="method">handleError</tt></b>(</nobr></td> | |
175 | <td><var>record</var>)</td></tr></table></dt> | |
176 | <dd> | |
177 | This method should be called from handlers when an exception is | |
178 | encountered during an <tt class="method">emit()</tt> call. By default it does nothing, | |
179 | which means that exceptions get silently ignored. This is what is | |
180 | mostly wanted for a logging system - most users will not care | |
181 | about errors in the logging system, they are more interested in | |
182 | application errors. You could, however, replace this with a custom | |
183 | handler if you wish. The specified record is the one which was being | |
184 | processed when the exception occurred. | |
185 | </dl> | |
186 | ||
187 | <P> | |
188 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
189 | <td><nobr><b><tt id='l2h-2505' xml:id='l2h-2505' class="method">format</tt></b>(</nobr></td> | |
190 | <td><var>record</var>)</td></tr></table></dt> | |
191 | <dd> | |
192 | Do formatting for a record - if a formatter is set, use it. | |
193 | Otherwise, use the default formatter for the module. | |
194 | </dl> | |
195 | ||
196 | <P> | |
197 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
198 | <td><nobr><b><tt id='l2h-2506' xml:id='l2h-2506' class="method">emit</tt></b>(</nobr></td> | |
199 | <td><var>record</var>)</td></tr></table></dt> | |
200 | <dd> | |
201 | Do whatever it takes to actually log the specified logging record. | |
202 | This version is intended to be implemented by subclasses and so | |
203 | raises a <tt class="exception">NotImplementedError</tt>. | |
204 | </dl> | |
205 | ||
206 | <P> | |
207 | ||
208 | <p><br /></p><hr class='online-navigation' /> | |
209 | <div class='online-navigation'> | |
210 | <!--Table of Child-Links--> | |
211 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
212 | ||
213 | <UL CLASS="ChildLinks"> | |
214 | <LI><A href="node346.html">6.29.5.1 StreamHandler</a> | |
215 | <LI><A href="node347.html">6.29.5.2 FileHandler</a> | |
216 | <LI><A href="node348.html">6.29.5.3 RotatingFileHandler</a> | |
217 | <LI><A href="node349.html">6.29.5.4 TimedRotatingFileHandler</a> | |
218 | <LI><A href="node350.html">6.29.5.5 SocketHandler</a> | |
219 | <LI><A href="node351.html">6.29.5.6 DatagramHandler</a> | |
220 | <LI><A href="node352.html">6.29.5.7 SysLogHandler</a> | |
221 | <LI><A href="node353.html">6.29.5.8 NTEventLogHandler</a> | |
222 | <LI><A href="node354.html">6.29.5.9 SMTPHandler</a> | |
223 | <LI><A href="node355.html">6.29.5.10 MemoryHandler</a> | |
224 | <LI><A href="node356.html">6.29.5.11 HTTPHandler</a> | |
225 | </ul> | |
226 | <!--End of Table of Child-Links--> | |
227 | </div> | |
228 | ||
229 | <DIV CLASS="navigation"> | |
230 | <div class='online-navigation'> | |
231 | <p></p><hr /> | |
232 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
233 | <tr> | |
234 | <td class='online-navigation'><a rel="prev" title="6.29.4 Sending and receiving" | |
235 | href="network-logging.html"><img src='../icons/previous.png' | |
236 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
237 | <td class='online-navigation'><a rel="parent" title="6.29 logging " | |
238 | href="module-logging.html"><img src='../icons/up.png' | |
239 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
240 | <td class='online-navigation'><a rel="next" title="6.29.5.1 StreamHandler" | |
241 | href="node346.html"><img src='../icons/next.png' | |
242 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
243 | <td align="center" width="100%">Python Library Reference</td> | |
244 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
245 | href="contents.html"><img src='../icons/contents.png' | |
246 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
247 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
248 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
249 | <td class='online-navigation'><a rel="index" title="Index" | |
250 | href="genindex.html"><img src='../icons/index.png' | |
251 | border='0' height='32' alt='Index' width='32' /></A></td> | |
252 | </tr></table> | |
253 | <div class='online-navigation'> | |
254 | <b class="navlabel">Previous:</b> | |
255 | <a class="sectref" rel="prev" href="network-logging.html">6.29.4 Sending and receiving</A> | |
256 | <b class="navlabel">Up:</b> | |
257 | <a class="sectref" rel="parent" href="module-logging.html">6.29 logging </A> | |
258 | <b class="navlabel">Next:</b> | |
259 | <a class="sectref" rel="next" href="node346.html">6.29.5.1 StreamHandler</A> | |
260 | </div> | |
261 | </div> | |
262 | <hr /> | |
263 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
264 | </DIV> | |
265 | <!--End of Navigation Panel--> | |
266 | <ADDRESS> | |
267 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
268 | </ADDRESS> | |
269 | </BODY> | |
270 | </HTML> |