blob: 3d05400603dc40da8cf0abf26e9ee2ab7b938faf [file] [log] [blame]
Vinay Sajip5dbca9c2011-04-08 11:40:38 +01001:mod:`logging.handlers` --- Logging handlers
2============================================
3
4.. module:: logging.handlers
5 :synopsis: Handlers for the logging module.
6
7
8.. moduleauthor:: Vinay Sajip <vinay_sajip@red-dove.com>
9.. sectionauthor:: Vinay Sajip <vinay_sajip@red-dove.com>
10
11.. sidebar:: Important
12
13 This page contains only reference information. For tutorials,
14 please see
15
16 * :ref:`Basic Tutorial <logging-basic-tutorial>`
17 * :ref:`Advanced Tutorial <logging-advanced-tutorial>`
18 * :ref:`Logging Cookbook <logging-cookbook>`
19
20.. currentmodule:: logging
21
22The following useful handlers are provided in the package. Note that three of
23the handlers (:class:`StreamHandler`, :class:`FileHandler` and
24:class:`NullHandler`) are actually defined in the :mod:`logging` module itself,
25but have been documented here along with the other handlers.
26
27.. _stream-handler:
28
29StreamHandler
30^^^^^^^^^^^^^
31
32The :class:`StreamHandler` class, located in the core :mod:`logging` package,
33sends logging output to streams such as *sys.stdout*, *sys.stderr* or any
34file-like object (or, more precisely, any object which supports :meth:`write`
35and :meth:`flush` methods).
36
37
38.. class:: StreamHandler(stream=None)
39
40 Returns a new instance of the :class:`StreamHandler` class. If *stream* is
41 specified, the instance will use it for logging output; otherwise, *sys.stderr*
42 will be used.
43
44
45 .. method:: emit(record)
46
47 If a formatter is specified, it is used to format the record. The record
48 is then written to the stream with a newline terminator. If exception
49 information is present, it is formatted using
50 :func:`traceback.print_exception` and appended to the stream.
51
52
53 .. method:: flush()
54
55 Flushes the stream by calling its :meth:`flush` method. Note that the
56 :meth:`close` method is inherited from :class:`Handler` and so does
57 no output, so an explicit :meth:`flush` call may be needed at times.
58
59.. _file-handler:
60
61FileHandler
62^^^^^^^^^^^
63
64The :class:`FileHandler` class, located in the core :mod:`logging` package,
65sends logging output to a disk file. It inherits the output functionality from
66:class:`StreamHandler`.
67
68
69.. class:: FileHandler(filename, mode='a', encoding=None, delay=False)
70
71 Returns a new instance of the :class:`FileHandler` class. The specified file is
72 opened and used as the stream for logging. If *mode* is not specified,
73 :const:`'a'` is used. If *encoding* is not *None*, it is used to open the file
74 with that encoding. If *delay* is true, then file opening is deferred until the
75 first call to :meth:`emit`. By default, the file grows indefinitely.
76
77 .. versionchanged:: 2.6
78 *delay* was added.
79
80 .. method:: close()
81
82 Closes the file.
83
84
85 .. method:: emit(record)
86
87 Outputs the record to the file.
88
89
90.. _null-handler:
91
92NullHandler
93^^^^^^^^^^^
94
95.. versionadded:: 2.7
96
97The :class:`NullHandler` class, located in the core :mod:`logging` package,
98does not do any formatting or output. It is essentially a 'no-op' handler
99for use by library developers.
100
101.. class:: NullHandler()
102
103 Returns a new instance of the :class:`NullHandler` class.
104
105 .. method:: emit(record)
106
107 This method does nothing.
108
109 .. method:: handle(record)
110
111 This method does nothing.
112
113 .. method:: createLock()
114
115 This method returns ``None`` for the lock, since there is no
116 underlying I/O to which access needs to be serialized.
117
118
119See :ref:`library-config` for more information on how to use
120:class:`NullHandler`.
121
122.. _watched-file-handler:
123
124WatchedFileHandler
125^^^^^^^^^^^^^^^^^^
126
127.. currentmodule:: logging.handlers
128
129.. versionadded:: 2.6
130
131The :class:`WatchedFileHandler` class, located in the :mod:`logging.handlers`
132module, is a :class:`FileHandler` which watches the file it is logging to. If
133the file changes, it is closed and reopened using the file name.
134
135A file change can happen because of usage of programs such as *newsyslog* and
136*logrotate* which perform log file rotation. This handler, intended for use
137under Unix/Linux, watches the file to see if it has changed since the last emit.
138(A file is deemed to have changed if its device or inode have changed.) If the
139file has changed, the old file stream is closed, and the file opened to get a
140new stream.
141
142This handler is not appropriate for use under Windows, because under Windows
143open log files cannot be moved or renamed - logging opens the files with
144exclusive locks - and so there is no need for such a handler. Furthermore,
145*ST_INO* is not supported under Windows; :func:`stat` always returns zero for
146this value.
147
148
149.. class:: WatchedFileHandler(filename[,mode[, encoding[, delay]]])
150
151 Returns a new instance of the :class:`WatchedFileHandler` class. The specified
152 file is opened and used as the stream for logging. If *mode* is not specified,
153 :const:`'a'` is used. If *encoding* is not *None*, it is used to open the file
154 with that encoding. If *delay* is true, then file opening is deferred until the
155 first call to :meth:`emit`. By default, the file grows indefinitely.
156
157
158 .. method:: emit(record)
159
160 Outputs the record to the file, but first checks to see if the file has
161 changed. If it has, the existing stream is flushed and closed and the
162 file opened again, before outputting the record to the file.
163
164.. _rotating-file-handler:
165
166RotatingFileHandler
167^^^^^^^^^^^^^^^^^^^
168
169The :class:`RotatingFileHandler` class, located in the :mod:`logging.handlers`
170module, supports rotation of disk log files.
171
172
173.. class:: RotatingFileHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=0)
174
175 Returns a new instance of the :class:`RotatingFileHandler` class. The specified
176 file is opened and used as the stream for logging. If *mode* is not specified,
177 ``'a'`` is used. If *encoding* is not *None*, it is used to open the file
178 with that encoding. If *delay* is true, then file opening is deferred until the
179 first call to :meth:`emit`. By default, the file grows indefinitely.
180
181 You can use the *maxBytes* and *backupCount* values to allow the file to
182 :dfn:`rollover` at a predetermined size. When the size is about to be exceeded,
183 the file is closed and a new file is silently opened for output. Rollover occurs
184 whenever the current log file is nearly *maxBytes* in length; if *maxBytes* is
185 zero, rollover never occurs. If *backupCount* is non-zero, the system will save
186 old log files by appending the extensions '.1', '.2' etc., to the filename. For
187 example, with a *backupCount* of 5 and a base file name of :file:`app.log`, you
188 would get :file:`app.log`, :file:`app.log.1`, :file:`app.log.2`, up to
189 :file:`app.log.5`. The file being written to is always :file:`app.log`. When
190 this file is filled, it is closed and renamed to :file:`app.log.1`, and if files
191 :file:`app.log.1`, :file:`app.log.2`, etc. exist, then they are renamed to
192 :file:`app.log.2`, :file:`app.log.3` etc. respectively.
193
194 .. versionchanged:: 2.6
195 *delay* was added.
196
197
198 .. method:: doRollover()
199
200 Does a rollover, as described above.
201
202
203 .. method:: emit(record)
204
205 Outputs the record to the file, catering for rollover as described
206 previously.
207
208.. _timed-rotating-file-handler:
209
210TimedRotatingFileHandler
211^^^^^^^^^^^^^^^^^^^^^^^^
212
213The :class:`TimedRotatingFileHandler` class, located in the
214:mod:`logging.handlers` module, supports rotation of disk log files at certain
215timed intervals.
216
217
218.. class:: TimedRotatingFileHandler(filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False)
219
220 Returns a new instance of the :class:`TimedRotatingFileHandler` class. The
221 specified file is opened and used as the stream for logging. On rotating it also
222 sets the filename suffix. Rotating happens based on the product of *when* and
223 *interval*.
224
225 You can use the *when* to specify the type of *interval*. The list of possible
226 values is below. Note that they are not case sensitive.
227
228 +----------------+-----------------------+
229 | Value | Type of interval |
230 +================+=======================+
231 | ``'S'`` | Seconds |
232 +----------------+-----------------------+
233 | ``'M'`` | Minutes |
234 +----------------+-----------------------+
235 | ``'H'`` | Hours |
236 +----------------+-----------------------+
237 | ``'D'`` | Days |
238 +----------------+-----------------------+
239 | ``'W'`` | Week day (0=Monday) |
240 +----------------+-----------------------+
241 | ``'midnight'`` | Roll over at midnight |
242 +----------------+-----------------------+
243
244 The system will save old log files by appending extensions to the filename.
245 The extensions are date-and-time based, using the strftime format
246 ``%Y-%m-%d_%H-%M-%S`` or a leading portion thereof, depending on the
247 rollover interval.
248
249 When computing the next rollover time for the first time (when the handler
250 is created), the last modification time of an existing log file, or else
251 the current time, is used to compute when the next rotation will occur.
252
253 If the *utc* argument is true, times in UTC will be used; otherwise
254 local time is used.
255
256 If *backupCount* is nonzero, at most *backupCount* files
257 will be kept, and if more would be created when rollover occurs, the oldest
258 one is deleted. The deletion logic uses the interval to determine which
259 files to delete, so changing the interval may leave old files lying around.
260
261 If *delay* is true, then file opening is deferred until the first call to
262 :meth:`emit`.
263
264 .. versionchanged:: 2.6
Vinay Sajip5df091a2011-11-06 22:37:17 +0000265 *delay* and *utc* were added.
Vinay Sajip5dbca9c2011-04-08 11:40:38 +0100266
267
268 .. method:: doRollover()
269
270 Does a rollover, as described above.
271
272
273 .. method:: emit(record)
274
275 Outputs the record to the file, catering for rollover as described above.
276
277
278.. _socket-handler:
279
280SocketHandler
281^^^^^^^^^^^^^
282
283The :class:`SocketHandler` class, located in the :mod:`logging.handlers` module,
284sends logging output to a network socket. The base class uses a TCP socket.
285
286
287.. class:: SocketHandler(host, port)
288
289 Returns a new instance of the :class:`SocketHandler` class intended to
290 communicate with a remote machine whose address is given by *host* and *port*.
291
292
293 .. method:: close()
294
295 Closes the socket.
296
297
298 .. method:: emit()
299
300 Pickles the record's attribute dictionary and writes it to the socket in
301 binary format. If there is an error with the socket, silently drops the
302 packet. If the connection was previously lost, re-establishes the
303 connection. To unpickle the record at the receiving end into a
304 :class:`LogRecord`, use the :func:`makeLogRecord` function.
305
306
307 .. method:: handleError()
308
309 Handles an error which has occurred during :meth:`emit`. The most likely
310 cause is a lost connection. Closes the socket so that we can retry on the
311 next event.
312
313
314 .. method:: makeSocket()
315
316 This is a factory method which allows subclasses to define the precise
317 type of socket they want. The default implementation creates a TCP socket
318 (:const:`socket.SOCK_STREAM`).
319
320
321 .. method:: makePickle(record)
322
323 Pickles the record's attribute dictionary in binary format with a length
324 prefix, and returns it ready for transmission across the socket.
325
326 Note that pickles aren't completely secure. If you are concerned about
327 security, you may want to override this method to implement a more secure
328 mechanism. For example, you can sign pickles using HMAC and then verify
329 them on the receiving end, or alternatively you can disable unpickling of
330 global objects on the receiving end.
331
332
333 .. method:: send(packet)
334
335 Send a pickled string *packet* to the socket. This function allows for
336 partial sends which can happen when the network is busy.
337
338
339 .. method:: createSocket()
340
341 Tries to create a socket; on failure, uses an exponential back-off
342 algorithm. On intial failure, the handler will drop the message it was
343 trying to send. When subsequent messages are handled by the same
344 instance, it will not try connecting until some time has passed. The
345 default parameters are such that the initial delay is one second, and if
346 after that delay the connection still can't be made, the handler will
347 double the delay each time up to a maximum of 30 seconds.
348
349 This behaviour is controlled by the following handler attributes:
350
351 * ``retryStart`` (initial delay, defaulting to 1.0 seconds).
352 * ``retryFactor`` (multiplier, defaulting to 2.0).
353 * ``retryMax`` (maximum delay, defaulting to 30.0 seconds).
354
355 This means that if the remote listener starts up *after* the handler has
356 been used, you could lose messages (since the handler won't even attempt
357 a connection until the delay has elapsed, but just silently drop messages
358 during the delay period).
359
360
361.. _datagram-handler:
362
363DatagramHandler
364^^^^^^^^^^^^^^^
365
366The :class:`DatagramHandler` class, located in the :mod:`logging.handlers`
367module, inherits from :class:`SocketHandler` to support sending logging messages
368over UDP sockets.
369
370
371.. class:: DatagramHandler(host, port)
372
373 Returns a new instance of the :class:`DatagramHandler` class intended to
374 communicate with a remote machine whose address is given by *host* and *port*.
375
376
377 .. method:: emit()
378
379 Pickles the record's attribute dictionary and writes it to the socket in
380 binary format. If there is an error with the socket, silently drops the
381 packet. To unpickle the record at the receiving end into a
382 :class:`LogRecord`, use the :func:`makeLogRecord` function.
383
384
385 .. method:: makeSocket()
386
387 The factory method of :class:`SocketHandler` is here overridden to create
388 a UDP socket (:const:`socket.SOCK_DGRAM`).
389
390
391 .. method:: send(s)
392
393 Send a pickled string to a socket.
394
395
396.. _syslog-handler:
397
398SysLogHandler
399^^^^^^^^^^^^^
400
401The :class:`SysLogHandler` class, located in the :mod:`logging.handlers` module,
402supports sending logging messages to a remote or local Unix syslog.
403
404
405.. class:: SysLogHandler(address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER, socktype=socket.SOCK_DGRAM)
406
407 Returns a new instance of the :class:`SysLogHandler` class intended to
408 communicate with a remote Unix machine whose address is given by *address* in
409 the form of a ``(host, port)`` tuple. If *address* is not specified,
410 ``('localhost', 514)`` is used. The address is used to open a socket. An
411 alternative to providing a ``(host, port)`` tuple is providing an address as a
412 string, for example '/dev/log'. In this case, a Unix domain socket is used to
413 send the message to the syslog. If *facility* is not specified,
414 :const:`LOG_USER` is used. The type of socket opened depends on the
415 *socktype* argument, which defaults to :const:`socket.SOCK_DGRAM` and thus
416 opens a UDP socket. To open a TCP socket (for use with the newer syslog
417 daemons such as rsyslog), specify a value of :const:`socket.SOCK_STREAM`.
418
419 Note that if your server is not listening on UDP port 514,
420 :class:`SysLogHandler` may appear not to work. In that case, check what
421 address you should be using for a domain socket - it's system dependent.
422 For example, on Linux it's usually '/dev/log' but on OS/X it's
423 '/var/run/syslog'. You'll need to check your platform and use the
424 appropriate address (you may need to do this check at runtime if your
425 application needs to run on several platforms). On Windows, you pretty
426 much have to use the UDP option.
427
428 .. versionchanged:: 2.7
429 *socktype* was added.
430
431
432 .. method:: close()
433
434 Closes the socket to the remote host.
435
436
437 .. method:: emit(record)
438
439 The record is formatted, and then sent to the syslog server. If exception
440 information is present, it is *not* sent to the server.
441
442
443 .. method:: encodePriority(facility, priority)
444
445 Encodes the facility and priority into an integer. You can pass in strings
446 or integers - if strings are passed, internal mapping dictionaries are
447 used to convert them to integers.
448
449 The symbolic ``LOG_`` values are defined in :class:`SysLogHandler` and
450 mirror the values defined in the ``sys/syslog.h`` header file.
451
452 **Priorities**
453
454 +--------------------------+---------------+
455 | Name (string) | Symbolic value|
456 +==========================+===============+
457 | ``alert`` | LOG_ALERT |
458 +--------------------------+---------------+
459 | ``crit`` or ``critical`` | LOG_CRIT |
460 +--------------------------+---------------+
461 | ``debug`` | LOG_DEBUG |
462 +--------------------------+---------------+
463 | ``emerg`` or ``panic`` | LOG_EMERG |
464 +--------------------------+---------------+
465 | ``err`` or ``error`` | LOG_ERR |
466 +--------------------------+---------------+
467 | ``info`` | LOG_INFO |
468 +--------------------------+---------------+
469 | ``notice`` | LOG_NOTICE |
470 +--------------------------+---------------+
471 | ``warn`` or ``warning`` | LOG_WARNING |
472 +--------------------------+---------------+
473
474 **Facilities**
475
476 +---------------+---------------+
477 | Name (string) | Symbolic value|
478 +===============+===============+
479 | ``auth`` | LOG_AUTH |
480 +---------------+---------------+
481 | ``authpriv`` | LOG_AUTHPRIV |
482 +---------------+---------------+
483 | ``cron`` | LOG_CRON |
484 +---------------+---------------+
485 | ``daemon`` | LOG_DAEMON |
486 +---------------+---------------+
487 | ``ftp`` | LOG_FTP |
488 +---------------+---------------+
489 | ``kern`` | LOG_KERN |
490 +---------------+---------------+
491 | ``lpr`` | LOG_LPR |
492 +---------------+---------------+
493 | ``mail`` | LOG_MAIL |
494 +---------------+---------------+
495 | ``news`` | LOG_NEWS |
496 +---------------+---------------+
497 | ``syslog`` | LOG_SYSLOG |
498 +---------------+---------------+
499 | ``user`` | LOG_USER |
500 +---------------+---------------+
501 | ``uucp`` | LOG_UUCP |
502 +---------------+---------------+
503 | ``local0`` | LOG_LOCAL0 |
504 +---------------+---------------+
505 | ``local1`` | LOG_LOCAL1 |
506 +---------------+---------------+
507 | ``local2`` | LOG_LOCAL2 |
508 +---------------+---------------+
509 | ``local3`` | LOG_LOCAL3 |
510 +---------------+---------------+
511 | ``local4`` | LOG_LOCAL4 |
512 +---------------+---------------+
513 | ``local5`` | LOG_LOCAL5 |
514 +---------------+---------------+
515 | ``local6`` | LOG_LOCAL6 |
516 +---------------+---------------+
517 | ``local7`` | LOG_LOCAL7 |
518 +---------------+---------------+
519
520 .. method:: mapPriority(levelname)
521
522 Maps a logging level name to a syslog priority name.
523 You may need to override this if you are using custom levels, or
524 if the default algorithm is not suitable for your needs. The
525 default algorithm maps ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR`` and
526 ``CRITICAL`` to the equivalent syslog names, and all other level
527 names to 'warning'.
528
529.. _nt-eventlog-handler:
530
531NTEventLogHandler
532^^^^^^^^^^^^^^^^^
533
534The :class:`NTEventLogHandler` class, located in the :mod:`logging.handlers`
535module, supports sending logging messages to a local Windows NT, Windows 2000 or
536Windows XP event log. Before you can use it, you need Mark Hammond's Win32
537extensions for Python installed.
538
539
540.. class:: NTEventLogHandler(appname, dllname=None, logtype='Application')
541
542 Returns a new instance of the :class:`NTEventLogHandler` class. The *appname* is
543 used to define the application name as it appears in the event log. An
544 appropriate registry entry is created using this name. The *dllname* should give
545 the fully qualified pathname of a .dll or .exe which contains message
546 definitions to hold in the log (if not specified, ``'win32service.pyd'`` is used
547 - this is installed with the Win32 extensions and contains some basic
548 placeholder message definitions. Note that use of these placeholders will make
549 your event logs big, as the entire message source is held in the log. If you
550 want slimmer logs, you have to pass in the name of your own .dll or .exe which
551 contains the message definitions you want to use in the event log). The
552 *logtype* is one of ``'Application'``, ``'System'`` or ``'Security'``, and
553 defaults to ``'Application'``.
554
555
556 .. method:: close()
557
558 At this point, you can remove the application name from the registry as a
559 source of event log entries. However, if you do this, you will not be able
560 to see the events as you intended in the Event Log Viewer - it needs to be
561 able to access the registry to get the .dll name. The current version does
562 not do this.
563
564
565 .. method:: emit(record)
566
567 Determines the message ID, event category and event type, and then logs
568 the message in the NT event log.
569
570
571 .. method:: getEventCategory(record)
572
573 Returns the event category for the record. Override this if you want to
574 specify your own categories. This version returns 0.
575
576
577 .. method:: getEventType(record)
578
579 Returns the event type for the record. Override this if you want to
580 specify your own types. This version does a mapping using the handler's
581 typemap attribute, which is set up in :meth:`__init__` to a dictionary
582 which contains mappings for :const:`DEBUG`, :const:`INFO`,
583 :const:`WARNING`, :const:`ERROR` and :const:`CRITICAL`. If you are using
584 your own levels, you will either need to override this method or place a
585 suitable dictionary in the handler's *typemap* attribute.
586
587
588 .. method:: getMessageID(record)
589
590 Returns the message ID for the record. If you are using your own messages,
591 you could do this by having the *msg* passed to the logger being an ID
592 rather than a format string. Then, in here, you could use a dictionary
593 lookup to get the message ID. This version returns 1, which is the base
594 message ID in :file:`win32service.pyd`.
595
596.. _smtp-handler:
597
598SMTPHandler
599^^^^^^^^^^^
600
601The :class:`SMTPHandler` class, located in the :mod:`logging.handlers` module,
602supports sending logging messages to an email address via SMTP.
603
604
605.. class:: SMTPHandler(mailhost, fromaddr, toaddrs, subject, credentials=None, secure=None)
606
607 Returns a new instance of the :class:`SMTPHandler` class. The instance is
608 initialized with the from and to addresses and subject line of the email.
609 The *toaddrs* should be a list of strings. To specify a non-standard SMTP
610 port, use the (host, port) tuple format for the *mailhost* argument. If you
611 use a string, the standard SMTP port is used. If your SMTP server requires
612 authentication, you can specify a (username, password) tuple for the
Vinay Sajip5d09ba42011-08-01 11:28:02 +0100613 *credentials* argument.
614
615 To specify the use of a secure protocol (TLS), pass in a tuple to the
616 *secure* argument. This will only be used when authentication credentials are
617 supplied. The tuple should be either an empty tuple, or a single-value tuple
618 with the name of a keyfile, or a 2-value tuple with the names of the keyfile
619 and certificate file. (This tuple is passed to the
620 :meth:`smtplib.SMTP.starttls` method.)
Vinay Sajip5dbca9c2011-04-08 11:40:38 +0100621
622 .. versionchanged:: 2.6
623 *credentials* was added.
624
625 .. versionchanged:: 2.7
626 *secure* was added.
627
628
629 .. method:: emit(record)
630
631 Formats the record and sends it to the specified addressees.
632
633
634 .. method:: getSubject(record)
635
636 If you want to specify a subject line which is record-dependent, override
637 this method.
638
639.. _memory-handler:
640
641MemoryHandler
642^^^^^^^^^^^^^
643
644The :class:`MemoryHandler` class, located in the :mod:`logging.handlers` module,
645supports buffering of logging records in memory, periodically flushing them to a
646:dfn:`target` handler. Flushing occurs whenever the buffer is full, or when an
647event of a certain severity or greater is seen.
648
649:class:`MemoryHandler` is a subclass of the more general
650:class:`BufferingHandler`, which is an abstract class. This buffers logging
651records in memory. Whenever each record is added to the buffer, a check is made
652by calling :meth:`shouldFlush` to see if the buffer should be flushed. If it
Vinay Sajip49d5fba2012-03-26 17:06:44 +0100653should, then :meth:`flush` is expected to do the flushing.
Vinay Sajip5dbca9c2011-04-08 11:40:38 +0100654
655
656.. class:: BufferingHandler(capacity)
657
658 Initializes the handler with a buffer of the specified capacity.
659
660
661 .. method:: emit(record)
662
663 Appends the record to the buffer. If :meth:`shouldFlush` returns true,
664 calls :meth:`flush` to process the buffer.
665
666
667 .. method:: flush()
668
669 You can override this to implement custom flushing behavior. This version
670 just zaps the buffer to empty.
671
672
673 .. method:: shouldFlush(record)
674
675 Returns true if the buffer is up to capacity. This method can be
676 overridden to implement custom flushing strategies.
677
678
679.. class:: MemoryHandler(capacity, flushLevel=ERROR, target=None)
680
681 Returns a new instance of the :class:`MemoryHandler` class. The instance is
682 initialized with a buffer size of *capacity*. If *flushLevel* is not specified,
683 :const:`ERROR` is used. If no *target* is specified, the target will need to be
684 set using :meth:`setTarget` before this handler does anything useful.
685
686
687 .. method:: close()
688
689 Calls :meth:`flush`, sets the target to :const:`None` and clears the
690 buffer.
691
692
693 .. method:: flush()
694
695 For a :class:`MemoryHandler`, flushing means just sending the buffered
696 records to the target, if there is one. The buffer is also cleared when
697 this happens. Override if you want different behavior.
698
699
700 .. method:: setTarget(target)
Vinay Sajip5dbca9c2011-04-08 11:40:38 +0100701
702 Sets the target handler for this handler.
703
704
705 .. method:: shouldFlush(record)
706
707 Checks for buffer full or a record at the *flushLevel* or higher.
708
709
710.. _http-handler:
711
712HTTPHandler
713^^^^^^^^^^^
714
715The :class:`HTTPHandler` class, located in the :mod:`logging.handlers` module,
716supports sending logging messages to a Web server, using either ``GET`` or
717``POST`` semantics.
718
719
720.. class:: HTTPHandler(host, url, method='GET')
721
722 Returns a new instance of the :class:`HTTPHandler` class. The *host* can be
723 of the form ``host:port``, should you need to use a specific port number.
724 If no *method* is specified, ``GET`` is used.
725
726
727 .. method:: emit(record)
728
729 Sends the record to the Web server as a percent-encoded dictionary.
730
731
732.. seealso::
733
734 Module :mod:`logging`
735 API reference for the logging module.
736
737 Module :mod:`logging.config`
738 Configuration API for the logging module.
739
740