| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1 | :mod:`logging.handlers` --- Logging handlers |
| 2 | ============================================ |
| 3 | |
| 4 | .. module:: logging.handlers |
| 5 | :synopsis: Handlers for the logging module. |
| 6 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 7 | .. moduleauthor:: Vinay Sajip <vinay_sajip@red-dove.com> |
| 8 | .. sectionauthor:: Vinay Sajip <vinay_sajip@red-dove.com> |
| 9 | |
| Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 10 | **Source code:** :source:`Lib/logging/handlers.py` |
| 11 | |
| Vinay Sajip | 01094e1 | 2010-12-19 13:41:26 +0000 | [diff] [blame] | 12 | .. sidebar:: Important |
| 13 | |
| 14 | This page contains only reference information. For tutorials, |
| 15 | please see |
| 16 | |
| 17 | * :ref:`Basic Tutorial <logging-basic-tutorial>` |
| 18 | * :ref:`Advanced Tutorial <logging-advanced-tutorial>` |
| 19 | * :ref:`Logging Cookbook <logging-cookbook>` |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 20 | |
| Vinay Sajip | 31b862d | 2013-09-05 23:01:07 +0100 | [diff] [blame] | 21 | -------------- |
| 22 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 23 | .. currentmodule:: logging |
| 24 | |
| Vinay Sajip | 01094e1 | 2010-12-19 13:41:26 +0000 | [diff] [blame] | 25 | The following useful handlers are provided in the package. Note that three of |
| 26 | the handlers (:class:`StreamHandler`, :class:`FileHandler` and |
| 27 | :class:`NullHandler`) are actually defined in the :mod:`logging` module itself, |
| 28 | but have been documented here along with the other handlers. |
| 29 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 30 | .. _stream-handler: |
| 31 | |
| 32 | StreamHandler |
| 33 | ^^^^^^^^^^^^^ |
| 34 | |
| 35 | The :class:`StreamHandler` class, located in the core :mod:`logging` package, |
| 36 | sends logging output to streams such as *sys.stdout*, *sys.stderr* or any |
| 37 | file-like object (or, more precisely, any object which supports :meth:`write` |
| 38 | and :meth:`flush` methods). |
| 39 | |
| 40 | |
| 41 | .. class:: StreamHandler(stream=None) |
| 42 | |
| 43 | Returns a new instance of the :class:`StreamHandler` class. If *stream* is |
| 44 | specified, the instance will use it for logging output; otherwise, *sys.stderr* |
| 45 | will be used. |
| 46 | |
| 47 | |
| 48 | .. method:: emit(record) |
| 49 | |
| 50 | If a formatter is specified, it is used to format the record. The record |
| Andre Delfino | 3e65830 | 2019-06-29 18:59:49 -0300 | [diff] [blame] | 51 | is then written to the stream followed by :attr:`terminator`. If exception information |
| Vinay Sajip | 689b68a | 2010-12-22 15:04:15 +0000 | [diff] [blame] | 52 | is present, it is formatted using :func:`traceback.print_exception` and |
| 53 | appended to the stream. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 54 | |
| 55 | |
| 56 | .. method:: flush() |
| 57 | |
| 58 | Flushes the stream by calling its :meth:`flush` method. Note that the |
| Vinay Sajip | 67f3977 | 2013-08-17 00:39:42 +0100 | [diff] [blame] | 59 | :meth:`close` method is inherited from :class:`~logging.Handler` and so |
| 60 | does no output, so an explicit :meth:`flush` call may be needed at times. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 61 | |
| Vinay Sajip | 2543f50 | 2017-07-30 10:41:45 +0100 | [diff] [blame] | 62 | .. method:: setStream(stream) |
| 63 | |
| 64 | Sets the instance's stream to the specified value, if it is different. |
| 65 | The old stream is flushed before the new stream is set. |
| 66 | |
| 67 | :param stream: The stream that the handler should use. |
| 68 | |
| 69 | :return: the old stream, if the stream was changed, or *None* if it wasn't. |
| 70 | |
| Andre Delfino | 18a2fc6 | 2019-06-29 18:57:39 -0300 | [diff] [blame] | 71 | .. versionadded:: 3.7 |
| Vinay Sajip | 2543f50 | 2017-07-30 10:41:45 +0100 | [diff] [blame] | 72 | |
| Andre Delfino | 3e65830 | 2019-06-29 18:59:49 -0300 | [diff] [blame] | 73 | .. attribute:: terminator |
| Vinay Sajip | 2543f50 | 2017-07-30 10:41:45 +0100 | [diff] [blame] | 74 | |
| Andre Delfino | 3e65830 | 2019-06-29 18:59:49 -0300 | [diff] [blame] | 75 | String used as the terminator when writing a formatted record to a stream. |
| 76 | Default value is ``'\n'``. |
| 77 | |
| 78 | If you don't want a newline termination, you can set the handler instance's |
| 79 | ``terminator`` attribute to the empty string. |
| 80 | |
| 81 | In earlier versions, the terminator was hardcoded as ``'\n'``. |
| 82 | |
| 83 | .. versionadded:: 3.2 |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 84 | |
| Vinay Sajip | 2543f50 | 2017-07-30 10:41:45 +0100 | [diff] [blame] | 85 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 86 | .. _file-handler: |
| 87 | |
| 88 | FileHandler |
| 89 | ^^^^^^^^^^^ |
| 90 | |
| 91 | The :class:`FileHandler` class, located in the core :mod:`logging` package, |
| 92 | sends logging output to a disk file. It inherits the output functionality from |
| 93 | :class:`StreamHandler`. |
| 94 | |
| 95 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 96 | .. class:: FileHandler(filename, mode='a', encoding=None, delay=False, errors=None) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 97 | |
| 98 | Returns a new instance of the :class:`FileHandler` class. The specified file is |
| 99 | opened and used as the stream for logging. If *mode* is not specified, |
| Serhiy Storchaka | ecf41da | 2016-10-19 16:29:26 +0300 | [diff] [blame] | 100 | :const:`'a'` is used. If *encoding* is not ``None``, it is used to open the file |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 101 | with that encoding. If *delay* is true, then file opening is deferred until the |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 102 | first call to :meth:`emit`. By default, the file grows indefinitely. If |
| 103 | *errors* is specified, it's used to determine how encoding errors are handled. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 104 | |
| Vinay Sajip | 638e622 | 2016-07-22 18:23:04 +0100 | [diff] [blame] | 105 | .. versionchanged:: 3.6 |
| 106 | As well as string values, :class:`~pathlib.Path` objects are also accepted |
| 107 | for the *filename* argument. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 108 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 109 | .. versionchanged:: 3.9 |
| 110 | The *errors* parameter was added. |
| 111 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 112 | .. method:: close() |
| 113 | |
| 114 | Closes the file. |
| 115 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 116 | .. method:: emit(record) |
| 117 | |
| 118 | Outputs the record to the file. |
| 119 | |
| Miss Islington (bot) | e35430b | 2022-01-07 14:15:25 -0800 | [diff] [blame] | 120 | Note that if the file was closed due to logging shutdown at exit and the file |
| 121 | mode is 'w', the record will not be emitted (see :issue:`42378`). |
| 122 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 123 | |
| 124 | .. _null-handler: |
| 125 | |
| 126 | NullHandler |
| 127 | ^^^^^^^^^^^ |
| 128 | |
| 129 | .. versionadded:: 3.1 |
| 130 | |
| 131 | The :class:`NullHandler` class, located in the core :mod:`logging` package, |
| 132 | does not do any formatting or output. It is essentially a 'no-op' handler |
| 133 | for use by library developers. |
| 134 | |
| 135 | .. class:: NullHandler() |
| 136 | |
| 137 | Returns a new instance of the :class:`NullHandler` class. |
| 138 | |
| 139 | .. method:: emit(record) |
| 140 | |
| 141 | This method does nothing. |
| 142 | |
| 143 | .. method:: handle(record) |
| 144 | |
| 145 | This method does nothing. |
| 146 | |
| 147 | .. method:: createLock() |
| 148 | |
| 149 | This method returns ``None`` for the lock, since there is no |
| 150 | underlying I/O to which access needs to be serialized. |
| 151 | |
| 152 | |
| 153 | See :ref:`library-config` for more information on how to use |
| 154 | :class:`NullHandler`. |
| 155 | |
| 156 | .. _watched-file-handler: |
| 157 | |
| 158 | WatchedFileHandler |
| 159 | ^^^^^^^^^^^^^^^^^^ |
| 160 | |
| 161 | .. currentmodule:: logging.handlers |
| 162 | |
| 163 | The :class:`WatchedFileHandler` class, located in the :mod:`logging.handlers` |
| 164 | module, is a :class:`FileHandler` which watches the file it is logging to. If |
| 165 | the file changes, it is closed and reopened using the file name. |
| 166 | |
| 167 | A file change can happen because of usage of programs such as *newsyslog* and |
| 168 | *logrotate* which perform log file rotation. This handler, intended for use |
| 169 | under Unix/Linux, watches the file to see if it has changed since the last emit. |
| 170 | (A file is deemed to have changed if its device or inode have changed.) If the |
| 171 | file has changed, the old file stream is closed, and the file opened to get a |
| 172 | new stream. |
| 173 | |
| 174 | This handler is not appropriate for use under Windows, because under Windows |
| 175 | open log files cannot be moved or renamed - logging opens the files with |
| 176 | exclusive locks - and so there is no need for such a handler. Furthermore, |
| Vinay Sajip | 67f3977 | 2013-08-17 00:39:42 +0100 | [diff] [blame] | 177 | *ST_INO* is not supported under Windows; :func:`~os.stat` always returns zero |
| 178 | for this value. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 179 | |
| 180 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 181 | .. class:: WatchedFileHandler(filename, mode='a', encoding=None, delay=False, errors=None) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 182 | |
| 183 | Returns a new instance of the :class:`WatchedFileHandler` class. The specified |
| 184 | file is opened and used as the stream for logging. If *mode* is not specified, |
| Serhiy Storchaka | ecf41da | 2016-10-19 16:29:26 +0300 | [diff] [blame] | 185 | :const:`'a'` is used. If *encoding* is not ``None``, it is used to open the file |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 186 | with that encoding. If *delay* is true, then file opening is deferred until the |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 187 | first call to :meth:`emit`. By default, the file grows indefinitely. If |
| 188 | *errors* is provided, it determines how encoding errors are handled. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 189 | |
| Vinay Sajip | 638e622 | 2016-07-22 18:23:04 +0100 | [diff] [blame] | 190 | .. versionchanged:: 3.6 |
| 191 | As well as string values, :class:`~pathlib.Path` objects are also accepted |
| 192 | for the *filename* argument. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 193 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 194 | .. versionchanged:: 3.9 |
| 195 | The *errors* parameter was added. |
| 196 | |
| Vinay Sajip | 29a1445 | 2015-10-01 20:54:41 +0100 | [diff] [blame] | 197 | .. method:: reopenIfNeeded() |
| 198 | |
| 199 | Checks to see if the file has changed. If it has, the existing stream is |
| 200 | flushed and closed and the file opened again, typically as a precursor to |
| 201 | outputting the record to the file. |
| 202 | |
| Berker Peksag | 6f038ad | 2015-10-07 07:54:23 +0300 | [diff] [blame] | 203 | .. versionadded:: 3.6 |
| 204 | |
| Vinay Sajip | 29a1445 | 2015-10-01 20:54:41 +0100 | [diff] [blame] | 205 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 206 | .. method:: emit(record) |
| 207 | |
| Vinay Sajip | 29a1445 | 2015-10-01 20:54:41 +0100 | [diff] [blame] | 208 | Outputs the record to the file, but first calls :meth:`reopenIfNeeded` to |
| 209 | reopen the file if it has changed. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 210 | |
| Vinay Sajip | 23b94d0 | 2012-01-04 12:02:26 +0000 | [diff] [blame] | 211 | .. _base-rotating-handler: |
| 212 | |
| 213 | BaseRotatingHandler |
| 214 | ^^^^^^^^^^^^^^^^^^^ |
| 215 | |
| 216 | The :class:`BaseRotatingHandler` class, located in the :mod:`logging.handlers` |
| 217 | module, is the base class for the rotating file handlers, |
| 218 | :class:`RotatingFileHandler` and :class:`TimedRotatingFileHandler`. You should |
| 219 | not need to instantiate this class, but it has attributes and methods you may |
| 220 | need to override. |
| 221 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 222 | .. class:: BaseRotatingHandler(filename, mode, encoding=None, delay=False, errors=None) |
| Vinay Sajip | 23b94d0 | 2012-01-04 12:02:26 +0000 | [diff] [blame] | 223 | |
| 224 | The parameters are as for :class:`FileHandler`. The attributes are: |
| 225 | |
| 226 | .. attribute:: namer |
| 227 | |
| 228 | If this attribute is set to a callable, the :meth:`rotation_filename` |
| 229 | method delegates to this callable. The parameters passed to the callable |
| 230 | are those passed to :meth:`rotation_filename`. |
| 231 | |
| 232 | .. note:: The namer function is called quite a few times during rollover, |
| 233 | so it should be as simple and as fast as possible. It should also |
| 234 | return the same output every time for a given input, otherwise the |
| 235 | rollover behaviour may not work as expected. |
| 236 | |
| Miss Islington (bot) | f84e2f6 | 2021-12-13 17:17:56 -0800 | [diff] [blame] | 237 | It's also worth noting that care should be taken when using a namer to |
| 238 | preserve certain attributes in the filename which are used during rotation. |
| 239 | For example, :class:`RotatingFileHandler` expects to have a set of log files |
| 240 | whose names contain successive integers, so that rotation works as expected, |
| 241 | and :class:`TimedRotatingFileHandler` deletes old log files (based on the |
| 242 | ``backupCount`` parameter passed to the handler's initializer) by determining |
| 243 | the oldest files to delete. For this to happen, the filenames should be |
| 244 | sortable using the date/time portion of the filename, and a namer needs to |
| 245 | respect this. (If a namer is wanted that doesn't respect this scheme, it will |
| 246 | need to be used in a subclass of :class:`TimedRotatingFileHandler` which |
| 247 | overrides the :meth:`~TimedRotatingFileHandler.getFilesToDelete` method to |
| 248 | fit in with the custom naming scheme.) |
| 249 | |
| Vinay Sajip | 23b94d0 | 2012-01-04 12:02:26 +0000 | [diff] [blame] | 250 | .. versionadded:: 3.3 |
| 251 | |
| 252 | |
| 253 | .. attribute:: BaseRotatingHandler.rotator |
| 254 | |
| 255 | If this attribute is set to a callable, the :meth:`rotate` method |
| 256 | delegates to this callable. The parameters passed to the callable are |
| 257 | those passed to :meth:`rotate`. |
| 258 | |
| 259 | .. versionadded:: 3.3 |
| 260 | |
| 261 | .. method:: BaseRotatingHandler.rotation_filename(default_name) |
| 262 | |
| 263 | Modify the filename of a log file when rotating. |
| 264 | |
| 265 | This is provided so that a custom filename can be provided. |
| 266 | |
| 267 | The default implementation calls the 'namer' attribute of the handler, |
| 268 | if it's callable, passing the default name to it. If the attribute isn't |
| Ezio Melotti | 226231c | 2012-01-18 05:40:00 +0200 | [diff] [blame] | 269 | callable (the default is ``None``), the name is returned unchanged. |
| Vinay Sajip | 23b94d0 | 2012-01-04 12:02:26 +0000 | [diff] [blame] | 270 | |
| 271 | :param default_name: The default name for the log file. |
| 272 | |
| 273 | .. versionadded:: 3.3 |
| 274 | |
| 275 | |
| 276 | .. method:: BaseRotatingHandler.rotate(source, dest) |
| 277 | |
| 278 | When rotating, rotate the current log. |
| 279 | |
| 280 | The default implementation calls the 'rotator' attribute of the handler, |
| 281 | if it's callable, passing the source and dest arguments to it. If the |
| Ezio Melotti | 226231c | 2012-01-18 05:40:00 +0200 | [diff] [blame] | 282 | attribute isn't callable (the default is ``None``), the source is simply |
| Vinay Sajip | 23b94d0 | 2012-01-04 12:02:26 +0000 | [diff] [blame] | 283 | renamed to the destination. |
| 284 | |
| 285 | :param source: The source filename. This is normally the base |
| Martin Panter | d21e0b5 | 2015-10-10 10:36:22 +0000 | [diff] [blame] | 286 | filename, e.g. 'test.log'. |
| Vinay Sajip | 23b94d0 | 2012-01-04 12:02:26 +0000 | [diff] [blame] | 287 | :param dest: The destination filename. This is normally |
| 288 | what the source is rotated to, e.g. 'test.log.1'. |
| 289 | |
| 290 | .. versionadded:: 3.3 |
| 291 | |
| 292 | The reason the attributes exist is to save you having to subclass - you can use |
| 293 | the same callables for instances of :class:`RotatingFileHandler` and |
| 294 | :class:`TimedRotatingFileHandler`. If either the namer or rotator callable |
| 295 | raises an exception, this will be handled in the same way as any other |
| 296 | exception during an :meth:`emit` call, i.e. via the :meth:`handleError` method |
| 297 | of the handler. |
| 298 | |
| 299 | If you need to make more significant changes to rotation processing, you can |
| 300 | override the methods. |
| 301 | |
| 302 | For an example, see :ref:`cookbook-rotator-namer`. |
| 303 | |
| 304 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 305 | .. _rotating-file-handler: |
| 306 | |
| 307 | RotatingFileHandler |
| 308 | ^^^^^^^^^^^^^^^^^^^ |
| 309 | |
| 310 | The :class:`RotatingFileHandler` class, located in the :mod:`logging.handlers` |
| 311 | module, supports rotation of disk log files. |
| 312 | |
| 313 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 314 | .. class:: RotatingFileHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 315 | |
| 316 | Returns a new instance of the :class:`RotatingFileHandler` class. The specified |
| 317 | file is opened and used as the stream for logging. If *mode* is not specified, |
| Serhiy Storchaka | ecf41da | 2016-10-19 16:29:26 +0300 | [diff] [blame] | 318 | ``'a'`` is used. If *encoding* is not ``None``, it is used to open the file |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 319 | with that encoding. If *delay* is true, then file opening is deferred until the |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 320 | first call to :meth:`emit`. By default, the file grows indefinitely. If |
| 321 | *errors* is provided, it determines how encoding errors are handled. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 322 | |
| 323 | You can use the *maxBytes* and *backupCount* values to allow the file to |
| 324 | :dfn:`rollover` at a predetermined size. When the size is about to be exceeded, |
| 325 | the file is closed and a new file is silently opened for output. Rollover occurs |
| Vinay Sajip | 53a21eb | 2016-12-31 11:06:57 +0000 | [diff] [blame] | 326 | whenever the current log file is nearly *maxBytes* in length; but if either of |
| 327 | *maxBytes* or *backupCount* is zero, rollover never occurs, so you generally want |
| 328 | to set *backupCount* to at least 1, and have a non-zero *maxBytes*. |
| 329 | When *backupCount* is non-zero, the system will save old log files by appending |
| 330 | the extensions '.1', '.2' etc., to the filename. For example, with a *backupCount* |
| 331 | of 5 and a base file name of :file:`app.log`, you would get :file:`app.log`, |
| Vinay Sajip | ff37cfe | 2015-01-23 21:19:04 +0000 | [diff] [blame] | 332 | :file:`app.log.1`, :file:`app.log.2`, up to :file:`app.log.5`. The file being |
| 333 | written to is always :file:`app.log`. When this file is filled, it is closed |
| 334 | and renamed to :file:`app.log.1`, and if files :file:`app.log.1`, |
| Vinay Sajip | 53a21eb | 2016-12-31 11:06:57 +0000 | [diff] [blame] | 335 | :file:`app.log.2`, etc. exist, then they are renamed to :file:`app.log.2`, |
| 336 | :file:`app.log.3` etc. respectively. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 337 | |
| Vinay Sajip | 638e622 | 2016-07-22 18:23:04 +0100 | [diff] [blame] | 338 | .. versionchanged:: 3.6 |
| 339 | As well as string values, :class:`~pathlib.Path` objects are also accepted |
| 340 | for the *filename* argument. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 341 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 342 | .. versionchanged:: 3.9 |
| 343 | The *errors* parameter was added. |
| 344 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 345 | .. method:: doRollover() |
| 346 | |
| 347 | Does a rollover, as described above. |
| 348 | |
| 349 | |
| 350 | .. method:: emit(record) |
| 351 | |
| 352 | Outputs the record to the file, catering for rollover as described |
| 353 | previously. |
| 354 | |
| 355 | .. _timed-rotating-file-handler: |
| 356 | |
| 357 | TimedRotatingFileHandler |
| 358 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 359 | |
| 360 | The :class:`TimedRotatingFileHandler` class, located in the |
| 361 | :mod:`logging.handlers` module, supports rotation of disk log files at certain |
| 362 | timed intervals. |
| 363 | |
| 364 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 365 | .. class:: TimedRotatingFileHandler(filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False, atTime=None, errors=None) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 366 | |
| 367 | Returns a new instance of the :class:`TimedRotatingFileHandler` class. The |
| 368 | specified file is opened and used as the stream for logging. On rotating it also |
| 369 | sets the filename suffix. Rotating happens based on the product of *when* and |
| 370 | *interval*. |
| 371 | |
| 372 | You can use the *when* to specify the type of *interval*. The list of possible |
| 373 | values is below. Note that they are not case sensitive. |
| 374 | |
| Vinay Sajip | dd30830 | 2016-08-24 17:49:15 +0100 | [diff] [blame] | 375 | +----------------+----------------------------+-------------------------+ |
| 376 | | Value | Type of interval | If/how *atTime* is used | |
| 377 | +================+============================+=========================+ |
| 378 | | ``'S'`` | Seconds | Ignored | |
| 379 | +----------------+----------------------------+-------------------------+ |
| 380 | | ``'M'`` | Minutes | Ignored | |
| 381 | +----------------+----------------------------+-------------------------+ |
| 382 | | ``'H'`` | Hours | Ignored | |
| 383 | +----------------+----------------------------+-------------------------+ |
| 384 | | ``'D'`` | Days | Ignored | |
| 385 | +----------------+----------------------------+-------------------------+ |
| 386 | | ``'W0'-'W6'`` | Weekday (0=Monday) | Used to compute initial | |
| 387 | | | | rollover time | |
| 388 | +----------------+----------------------------+-------------------------+ |
| 389 | | ``'midnight'`` | Roll over at midnight, if | Used to compute initial | |
| 390 | | | *atTime* not specified, | rollover time | |
| 391 | | | else at time *atTime* | | |
| 392 | +----------------+----------------------------+-------------------------+ |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 393 | |
| Vinay Sajip | 832d99b | 2013-03-08 23:24:30 +0000 | [diff] [blame] | 394 | When using weekday-based rotation, specify 'W0' for Monday, 'W1' for |
| 395 | Tuesday, and so on up to 'W6' for Sunday. In this case, the value passed for |
| 396 | *interval* isn't used. |
| 397 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 398 | The system will save old log files by appending extensions to the filename. |
| 399 | The extensions are date-and-time based, using the strftime format |
| 400 | ``%Y-%m-%d_%H-%M-%S`` or a leading portion thereof, depending on the |
| 401 | rollover interval. |
| 402 | |
| 403 | When computing the next rollover time for the first time (when the handler |
| 404 | is created), the last modification time of an existing log file, or else |
| 405 | the current time, is used to compute when the next rotation will occur. |
| 406 | |
| 407 | If the *utc* argument is true, times in UTC will be used; otherwise |
| 408 | local time is used. |
| 409 | |
| 410 | If *backupCount* is nonzero, at most *backupCount* files |
| 411 | will be kept, and if more would be created when rollover occurs, the oldest |
| 412 | one is deleted. The deletion logic uses the interval to determine which |
| 413 | files to delete, so changing the interval may leave old files lying around. |
| 414 | |
| 415 | If *delay* is true, then file opening is deferred until the first call to |
| 416 | :meth:`emit`. |
| 417 | |
| Vinay Sajip | a713079 | 2013-04-12 17:04:23 +0100 | [diff] [blame] | 418 | If *atTime* is not ``None``, it must be a ``datetime.time`` instance which |
| 419 | specifies the time of day when rollover occurs, for the cases where rollover |
| Vinay Sajip | dd30830 | 2016-08-24 17:49:15 +0100 | [diff] [blame] | 420 | is set to happen "at midnight" or "on a particular weekday". Note that in |
| 421 | these cases, the *atTime* value is effectively used to compute the *initial* |
| 422 | rollover, and subsequent rollovers would be calculated via the normal |
| 423 | interval calculation. |
| 424 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 425 | If *errors* is specified, it's used to determine how encoding errors are |
| 426 | handled. |
| 427 | |
| Vinay Sajip | dd30830 | 2016-08-24 17:49:15 +0100 | [diff] [blame] | 428 | .. note:: Calculation of the initial rollover time is done when the handler |
| 429 | is initialised. Calculation of subsequent rollover times is done only |
| 430 | when rollover occurs, and rollover occurs only when emitting output. If |
| 431 | this is not kept in mind, it might lead to some confusion. For example, |
| 432 | if an interval of "every minute" is set, that does not mean you will |
| 433 | always see log files with times (in the filename) separated by a minute; |
| 434 | if, during application execution, logging output is generated more |
| 435 | frequently than once a minute, *then* you can expect to see log files |
| 436 | with times separated by a minute. If, on the other hand, logging messages |
| 437 | are only output once every five minutes (say), then there will be gaps in |
| 438 | the file times corresponding to the minutes where no output (and hence no |
| 439 | rollover) occurred. |
| Vinay Sajip | a713079 | 2013-04-12 17:04:23 +0100 | [diff] [blame] | 440 | |
| 441 | .. versionchanged:: 3.4 |
| 442 | *atTime* parameter was added. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 443 | |
| Vinay Sajip | 638e622 | 2016-07-22 18:23:04 +0100 | [diff] [blame] | 444 | .. versionchanged:: 3.6 |
| 445 | As well as string values, :class:`~pathlib.Path` objects are also accepted |
| 446 | for the *filename* argument. |
| 447 | |
| Vinay Sajip | ca7b504 | 2019-06-17 17:40:52 +0100 | [diff] [blame] | 448 | .. versionchanged:: 3.9 |
| 449 | The *errors* parameter was added. |
| 450 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 451 | .. method:: doRollover() |
| 452 | |
| 453 | Does a rollover, as described above. |
| 454 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 455 | .. method:: emit(record) |
| 456 | |
| 457 | Outputs the record to the file, catering for rollover as described above. |
| 458 | |
| Miss Islington (bot) | f84e2f6 | 2021-12-13 17:17:56 -0800 | [diff] [blame] | 459 | .. method:: getFilesToDelete() |
| 460 | |
| 461 | Returns a list of filenames which should be deleted as part of rollover. These |
| 462 | are the absolute paths of the oldest backup log files written by the handler. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 463 | |
| 464 | .. _socket-handler: |
| 465 | |
| 466 | SocketHandler |
| 467 | ^^^^^^^^^^^^^ |
| 468 | |
| 469 | The :class:`SocketHandler` class, located in the :mod:`logging.handlers` module, |
| 470 | sends logging output to a network socket. The base class uses a TCP socket. |
| 471 | |
| 472 | |
| 473 | .. class:: SocketHandler(host, port) |
| 474 | |
| 475 | Returns a new instance of the :class:`SocketHandler` class intended to |
| 476 | communicate with a remote machine whose address is given by *host* and *port*. |
| 477 | |
| Vinay Sajip | 5421f35 | 2013-09-27 18:18:28 +0100 | [diff] [blame] | 478 | .. versionchanged:: 3.4 |
| 479 | If ``port`` is specified as ``None``, a Unix domain socket is created |
| 480 | using the value in ``host`` - otherwise, a TCP socket is created. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 481 | |
| 482 | .. method:: close() |
| 483 | |
| 484 | Closes the socket. |
| 485 | |
| 486 | |
| 487 | .. method:: emit() |
| 488 | |
| 489 | Pickles the record's attribute dictionary and writes it to the socket in |
| 490 | binary format. If there is an error with the socket, silently drops the |
| 491 | packet. If the connection was previously lost, re-establishes the |
| 492 | connection. To unpickle the record at the receiving end into a |
| Vinay Sajip | 67f3977 | 2013-08-17 00:39:42 +0100 | [diff] [blame] | 493 | :class:`~logging.LogRecord`, use the :func:`~logging.makeLogRecord` |
| 494 | function. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 495 | |
| 496 | |
| 497 | .. method:: handleError() |
| 498 | |
| 499 | Handles an error which has occurred during :meth:`emit`. The most likely |
| 500 | cause is a lost connection. Closes the socket so that we can retry on the |
| 501 | next event. |
| 502 | |
| 503 | |
| 504 | .. method:: makeSocket() |
| 505 | |
| 506 | This is a factory method which allows subclasses to define the precise |
| 507 | type of socket they want. The default implementation creates a TCP socket |
| 508 | (:const:`socket.SOCK_STREAM`). |
| 509 | |
| 510 | |
| 511 | .. method:: makePickle(record) |
| 512 | |
| 513 | Pickles the record's attribute dictionary in binary format with a length |
| Vinay Sajip | f06b569 | 2019-06-19 15:29:57 +0100 | [diff] [blame] | 514 | prefix, and returns it ready for transmission across the socket. The |
| 515 | details of this operation are equivalent to:: |
| 516 | |
| 517 | data = pickle.dumps(record_attr_dict, 1) |
| 518 | datalen = struct.pack('>L', len(data)) |
| 519 | return datalen + data |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 520 | |
| 521 | Note that pickles aren't completely secure. If you are concerned about |
| 522 | security, you may want to override this method to implement a more secure |
| 523 | mechanism. For example, you can sign pickles using HMAC and then verify |
| 524 | them on the receiving end, or alternatively you can disable unpickling of |
| 525 | global objects on the receiving end. |
| 526 | |
| Georg Brandl | 08e278a | 2011-02-15 12:44:43 +0000 | [diff] [blame] | 527 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 528 | .. method:: send(packet) |
| 529 | |
| Vinay Sajip | f06b569 | 2019-06-19 15:29:57 +0100 | [diff] [blame] | 530 | Send a pickled byte-string *packet* to the socket. The format of the sent |
| 531 | byte-string is as described in the documentation for |
| 532 | :meth:`~SocketHandler.makePickle`. |
| 533 | |
| 534 | This function allows for partial sends, which can happen when the network |
| 535 | is busy. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 536 | |
| Georg Brandl | 08e278a | 2011-02-15 12:44:43 +0000 | [diff] [blame] | 537 | |
| Georg Brandl | dbb9585 | 2011-02-15 12:41:17 +0000 | [diff] [blame] | 538 | .. method:: createSocket() |
| 539 | |
| 540 | Tries to create a socket; on failure, uses an exponential back-off |
| Donald Stufft | 8b852f1 | 2014-05-20 12:58:38 -0400 | [diff] [blame] | 541 | algorithm. On initial failure, the handler will drop the message it was |
| Georg Brandl | dbb9585 | 2011-02-15 12:41:17 +0000 | [diff] [blame] | 542 | trying to send. When subsequent messages are handled by the same |
| 543 | instance, it will not try connecting until some time has passed. The |
| 544 | default parameters are such that the initial delay is one second, and if |
| 545 | after that delay the connection still can't be made, the handler will |
| 546 | double the delay each time up to a maximum of 30 seconds. |
| 547 | |
| 548 | This behaviour is controlled by the following handler attributes: |
| 549 | |
| 550 | * ``retryStart`` (initial delay, defaulting to 1.0 seconds). |
| 551 | * ``retryFactor`` (multiplier, defaulting to 2.0). |
| 552 | * ``retryMax`` (maximum delay, defaulting to 30.0 seconds). |
| 553 | |
| 554 | This means that if the remote listener starts up *after* the handler has |
| 555 | been used, you could lose messages (since the handler won't even attempt |
| 556 | a connection until the delay has elapsed, but just silently drop messages |
| 557 | during the delay period). |
| Georg Brandl | 08e278a | 2011-02-15 12:44:43 +0000 | [diff] [blame] | 558 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 559 | |
| 560 | .. _datagram-handler: |
| 561 | |
| 562 | DatagramHandler |
| 563 | ^^^^^^^^^^^^^^^ |
| 564 | |
| 565 | The :class:`DatagramHandler` class, located in the :mod:`logging.handlers` |
| 566 | module, inherits from :class:`SocketHandler` to support sending logging messages |
| 567 | over UDP sockets. |
| 568 | |
| 569 | |
| 570 | .. class:: DatagramHandler(host, port) |
| 571 | |
| 572 | Returns a new instance of the :class:`DatagramHandler` class intended to |
| 573 | communicate with a remote machine whose address is given by *host* and *port*. |
| 574 | |
| Vinay Sajip | 5421f35 | 2013-09-27 18:18:28 +0100 | [diff] [blame] | 575 | .. versionchanged:: 3.4 |
| 576 | If ``port`` is specified as ``None``, a Unix domain socket is created |
| Mike DePalatis | 233de02 | 2018-03-30 03:36:06 -0400 | [diff] [blame] | 577 | using the value in ``host`` - otherwise, a UDP socket is created. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 578 | |
| 579 | .. method:: emit() |
| 580 | |
| 581 | Pickles the record's attribute dictionary and writes it to the socket in |
| 582 | binary format. If there is an error with the socket, silently drops the |
| 583 | packet. To unpickle the record at the receiving end into a |
| Vinay Sajip | 67f3977 | 2013-08-17 00:39:42 +0100 | [diff] [blame] | 584 | :class:`~logging.LogRecord`, use the :func:`~logging.makeLogRecord` |
| 585 | function. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 586 | |
| 587 | |
| 588 | .. method:: makeSocket() |
| 589 | |
| 590 | The factory method of :class:`SocketHandler` is here overridden to create |
| 591 | a UDP socket (:const:`socket.SOCK_DGRAM`). |
| 592 | |
| 593 | |
| 594 | .. method:: send(s) |
| 595 | |
| Vinay Sajip | f06b569 | 2019-06-19 15:29:57 +0100 | [diff] [blame] | 596 | Send a pickled byte-string to a socket. The format of the sent byte-string |
| 597 | is as described in the documentation for :meth:`SocketHandler.makePickle`. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 598 | |
| 599 | |
| 600 | .. _syslog-handler: |
| 601 | |
| 602 | SysLogHandler |
| 603 | ^^^^^^^^^^^^^ |
| 604 | |
| 605 | The :class:`SysLogHandler` class, located in the :mod:`logging.handlers` module, |
| 606 | supports sending logging messages to a remote or local Unix syslog. |
| 607 | |
| 608 | |
| 609 | .. class:: SysLogHandler(address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER, socktype=socket.SOCK_DGRAM) |
| 610 | |
| 611 | Returns a new instance of the :class:`SysLogHandler` class intended to |
| 612 | communicate with a remote Unix machine whose address is given by *address* in |
| 613 | the form of a ``(host, port)`` tuple. If *address* is not specified, |
| 614 | ``('localhost', 514)`` is used. The address is used to open a socket. An |
| 615 | alternative to providing a ``(host, port)`` tuple is providing an address as a |
| 616 | string, for example '/dev/log'. In this case, a Unix domain socket is used to |
| 617 | send the message to the syslog. If *facility* is not specified, |
| 618 | :const:`LOG_USER` is used. The type of socket opened depends on the |
| 619 | *socktype* argument, which defaults to :const:`socket.SOCK_DGRAM` and thus |
| 620 | opens a UDP socket. To open a TCP socket (for use with the newer syslog |
| 621 | daemons such as rsyslog), specify a value of :const:`socket.SOCK_STREAM`. |
| 622 | |
| 623 | Note that if your server is not listening on UDP port 514, |
| 624 | :class:`SysLogHandler` may appear not to work. In that case, check what |
| 625 | address you should be using for a domain socket - it's system dependent. |
| 626 | For example, on Linux it's usually '/dev/log' but on OS/X it's |
| 627 | '/var/run/syslog'. You'll need to check your platform and use the |
| 628 | appropriate address (you may need to do this check at runtime if your |
| 629 | application needs to run on several platforms). On Windows, you pretty |
| 630 | much have to use the UDP option. |
| 631 | |
| 632 | .. versionchanged:: 3.2 |
| 633 | *socktype* was added. |
| 634 | |
| 635 | |
| 636 | .. method:: close() |
| 637 | |
| 638 | Closes the socket to the remote host. |
| 639 | |
| 640 | |
| 641 | .. method:: emit(record) |
| 642 | |
| 643 | The record is formatted, and then sent to the syslog server. If exception |
| 644 | information is present, it is *not* sent to the server. |
| 645 | |
| Vinay Sajip | 645e458 | 2011-06-10 18:52:50 +0100 | [diff] [blame] | 646 | .. versionchanged:: 3.2.1 |
| 647 | (See: :issue:`12168`.) In earlier versions, the message sent to the |
| 648 | syslog daemons was always terminated with a NUL byte, because early |
| 649 | versions of these daemons expected a NUL terminated message - even |
| Serhiy Storchaka | 0a36ac1 | 2018-05-31 07:39:00 +0300 | [diff] [blame] | 650 | though it's not in the relevant specification (:rfc:`5424`). More recent |
| Vinay Sajip | 645e458 | 2011-06-10 18:52:50 +0100 | [diff] [blame] | 651 | versions of these daemons don't expect the NUL byte but strip it off |
| 652 | if it's there, and even more recent daemons (which adhere more closely |
| 653 | to RFC 5424) pass the NUL byte on as part of the message. |
| 654 | |
| 655 | To enable easier handling of syslog messages in the face of all these |
| 656 | differing daemon behaviours, the appending of the NUL byte has been |
| 657 | made configurable, through the use of a class-level attribute, |
| 658 | ``append_nul``. This defaults to ``True`` (preserving the existing |
| 659 | behaviour) but can be set to ``False`` on a ``SysLogHandler`` instance |
| 660 | in order for that instance to *not* append the NUL terminator. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 661 | |
| Vinay Sajip | 2353e35 | 2011-06-27 15:40:06 +0100 | [diff] [blame] | 662 | .. versionchanged:: 3.3 |
| 663 | (See: :issue:`12419`.) In earlier versions, there was no facility for |
| 664 | an "ident" or "tag" prefix to identify the source of the message. This |
| 665 | can now be specified using a class-level attribute, defaulting to |
| 666 | ``""`` to preserve existing behaviour, but which can be overridden on |
| 667 | a ``SysLogHandler`` instance in order for that instance to prepend |
| 668 | the ident to every message handled. Note that the provided ident must |
| 669 | be text, not bytes, and is prepended to the message exactly as is. |
| 670 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 671 | .. method:: encodePriority(facility, priority) |
| 672 | |
| 673 | Encodes the facility and priority into an integer. You can pass in strings |
| 674 | or integers - if strings are passed, internal mapping dictionaries are |
| 675 | used to convert them to integers. |
| 676 | |
| 677 | The symbolic ``LOG_`` values are defined in :class:`SysLogHandler` and |
| 678 | mirror the values defined in the ``sys/syslog.h`` header file. |
| 679 | |
| 680 | **Priorities** |
| 681 | |
| 682 | +--------------------------+---------------+ |
| 683 | | Name (string) | Symbolic value| |
| 684 | +==========================+===============+ |
| 685 | | ``alert`` | LOG_ALERT | |
| 686 | +--------------------------+---------------+ |
| 687 | | ``crit`` or ``critical`` | LOG_CRIT | |
| 688 | +--------------------------+---------------+ |
| 689 | | ``debug`` | LOG_DEBUG | |
| 690 | +--------------------------+---------------+ |
| 691 | | ``emerg`` or ``panic`` | LOG_EMERG | |
| 692 | +--------------------------+---------------+ |
| 693 | | ``err`` or ``error`` | LOG_ERR | |
| 694 | +--------------------------+---------------+ |
| 695 | | ``info`` | LOG_INFO | |
| 696 | +--------------------------+---------------+ |
| 697 | | ``notice`` | LOG_NOTICE | |
| 698 | +--------------------------+---------------+ |
| 699 | | ``warn`` or ``warning`` | LOG_WARNING | |
| 700 | +--------------------------+---------------+ |
| 701 | |
| 702 | **Facilities** |
| 703 | |
| 704 | +---------------+---------------+ |
| 705 | | Name (string) | Symbolic value| |
| 706 | +===============+===============+ |
| 707 | | ``auth`` | LOG_AUTH | |
| 708 | +---------------+---------------+ |
| 709 | | ``authpriv`` | LOG_AUTHPRIV | |
| 710 | +---------------+---------------+ |
| 711 | | ``cron`` | LOG_CRON | |
| 712 | +---------------+---------------+ |
| 713 | | ``daemon`` | LOG_DAEMON | |
| 714 | +---------------+---------------+ |
| 715 | | ``ftp`` | LOG_FTP | |
| 716 | +---------------+---------------+ |
| 717 | | ``kern`` | LOG_KERN | |
| 718 | +---------------+---------------+ |
| 719 | | ``lpr`` | LOG_LPR | |
| 720 | +---------------+---------------+ |
| 721 | | ``mail`` | LOG_MAIL | |
| 722 | +---------------+---------------+ |
| 723 | | ``news`` | LOG_NEWS | |
| 724 | +---------------+---------------+ |
| 725 | | ``syslog`` | LOG_SYSLOG | |
| 726 | +---------------+---------------+ |
| 727 | | ``user`` | LOG_USER | |
| 728 | +---------------+---------------+ |
| 729 | | ``uucp`` | LOG_UUCP | |
| 730 | +---------------+---------------+ |
| 731 | | ``local0`` | LOG_LOCAL0 | |
| 732 | +---------------+---------------+ |
| 733 | | ``local1`` | LOG_LOCAL1 | |
| 734 | +---------------+---------------+ |
| 735 | | ``local2`` | LOG_LOCAL2 | |
| 736 | +---------------+---------------+ |
| 737 | | ``local3`` | LOG_LOCAL3 | |
| 738 | +---------------+---------------+ |
| 739 | | ``local4`` | LOG_LOCAL4 | |
| 740 | +---------------+---------------+ |
| 741 | | ``local5`` | LOG_LOCAL5 | |
| 742 | +---------------+---------------+ |
| 743 | | ``local6`` | LOG_LOCAL6 | |
| 744 | +---------------+---------------+ |
| 745 | | ``local7`` | LOG_LOCAL7 | |
| 746 | +---------------+---------------+ |
| 747 | |
| 748 | .. method:: mapPriority(levelname) |
| 749 | |
| 750 | Maps a logging level name to a syslog priority name. |
| 751 | You may need to override this if you are using custom levels, or |
| 752 | if the default algorithm is not suitable for your needs. The |
| 753 | default algorithm maps ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR`` and |
| 754 | ``CRITICAL`` to the equivalent syslog names, and all other level |
| 755 | names to 'warning'. |
| 756 | |
| 757 | .. _nt-eventlog-handler: |
| 758 | |
| 759 | NTEventLogHandler |
| 760 | ^^^^^^^^^^^^^^^^^ |
| 761 | |
| 762 | The :class:`NTEventLogHandler` class, located in the :mod:`logging.handlers` |
| 763 | module, supports sending logging messages to a local Windows NT, Windows 2000 or |
| 764 | Windows XP event log. Before you can use it, you need Mark Hammond's Win32 |
| 765 | extensions for Python installed. |
| 766 | |
| 767 | |
| 768 | .. class:: NTEventLogHandler(appname, dllname=None, logtype='Application') |
| 769 | |
| 770 | Returns a new instance of the :class:`NTEventLogHandler` class. The *appname* is |
| 771 | used to define the application name as it appears in the event log. An |
| 772 | appropriate registry entry is created using this name. The *dllname* should give |
| 773 | the fully qualified pathname of a .dll or .exe which contains message |
| 774 | definitions to hold in the log (if not specified, ``'win32service.pyd'`` is used |
| 775 | - this is installed with the Win32 extensions and contains some basic |
| 776 | placeholder message definitions. Note that use of these placeholders will make |
| 777 | your event logs big, as the entire message source is held in the log. If you |
| 778 | want slimmer logs, you have to pass in the name of your own .dll or .exe which |
| 779 | contains the message definitions you want to use in the event log). The |
| 780 | *logtype* is one of ``'Application'``, ``'System'`` or ``'Security'``, and |
| 781 | defaults to ``'Application'``. |
| 782 | |
| 783 | |
| 784 | .. method:: close() |
| 785 | |
| 786 | At this point, you can remove the application name from the registry as a |
| 787 | source of event log entries. However, if you do this, you will not be able |
| 788 | to see the events as you intended in the Event Log Viewer - it needs to be |
| 789 | able to access the registry to get the .dll name. The current version does |
| 790 | not do this. |
| 791 | |
| 792 | |
| 793 | .. method:: emit(record) |
| 794 | |
| 795 | Determines the message ID, event category and event type, and then logs |
| 796 | the message in the NT event log. |
| 797 | |
| 798 | |
| 799 | .. method:: getEventCategory(record) |
| 800 | |
| 801 | Returns the event category for the record. Override this if you want to |
| 802 | specify your own categories. This version returns 0. |
| 803 | |
| 804 | |
| 805 | .. method:: getEventType(record) |
| 806 | |
| 807 | Returns the event type for the record. Override this if you want to |
| 808 | specify your own types. This version does a mapping using the handler's |
| 809 | typemap attribute, which is set up in :meth:`__init__` to a dictionary |
| 810 | which contains mappings for :const:`DEBUG`, :const:`INFO`, |
| 811 | :const:`WARNING`, :const:`ERROR` and :const:`CRITICAL`. If you are using |
| 812 | your own levels, you will either need to override this method or place a |
| 813 | suitable dictionary in the handler's *typemap* attribute. |
| 814 | |
| 815 | |
| 816 | .. method:: getMessageID(record) |
| 817 | |
| 818 | Returns the message ID for the record. If you are using your own messages, |
| 819 | you could do this by having the *msg* passed to the logger being an ID |
| 820 | rather than a format string. Then, in here, you could use a dictionary |
| 821 | lookup to get the message ID. This version returns 1, which is the base |
| 822 | message ID in :file:`win32service.pyd`. |
| 823 | |
| 824 | .. _smtp-handler: |
| 825 | |
| 826 | SMTPHandler |
| 827 | ^^^^^^^^^^^ |
| 828 | |
| 829 | The :class:`SMTPHandler` class, located in the :mod:`logging.handlers` module, |
| 830 | supports sending logging messages to an email address via SMTP. |
| 831 | |
| 832 | |
| Vinay Sajip | 38a12af | 2012-03-26 17:17:39 +0100 | [diff] [blame] | 833 | .. class:: SMTPHandler(mailhost, fromaddr, toaddrs, subject, credentials=None, secure=None, timeout=1.0) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 834 | |
| 835 | Returns a new instance of the :class:`SMTPHandler` class. The instance is |
| 836 | initialized with the from and to addresses and subject line of the email. The |
| 837 | *toaddrs* should be a list of strings. To specify a non-standard SMTP port, use |
| 838 | the (host, port) tuple format for the *mailhost* argument. If you use a string, |
| 839 | the standard SMTP port is used. If your SMTP server requires authentication, you |
| 840 | can specify a (username, password) tuple for the *credentials* argument. |
| 841 | |
| Vinay Sajip | 9525956 | 2011-08-01 11:31:52 +0100 | [diff] [blame] | 842 | To specify the use of a secure protocol (TLS), pass in a tuple to the |
| 843 | *secure* argument. This will only be used when authentication credentials are |
| 844 | supplied. The tuple should be either an empty tuple, or a single-value tuple |
| 845 | with the name of a keyfile, or a 2-value tuple with the names of the keyfile |
| 846 | and certificate file. (This tuple is passed to the |
| 847 | :meth:`smtplib.SMTP.starttls` method.) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 848 | |
| Vinay Sajip | 38a12af | 2012-03-26 17:17:39 +0100 | [diff] [blame] | 849 | A timeout can be specified for communication with the SMTP server using the |
| 850 | *timeout* argument. |
| 851 | |
| 852 | .. versionadded:: 3.3 |
| 853 | The *timeout* argument was added. |
| 854 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 855 | .. method:: emit(record) |
| 856 | |
| 857 | Formats the record and sends it to the specified addressees. |
| 858 | |
| 859 | |
| 860 | .. method:: getSubject(record) |
| 861 | |
| 862 | If you want to specify a subject line which is record-dependent, override |
| 863 | this method. |
| 864 | |
| 865 | .. _memory-handler: |
| 866 | |
| 867 | MemoryHandler |
| 868 | ^^^^^^^^^^^^^ |
| 869 | |
| 870 | The :class:`MemoryHandler` class, located in the :mod:`logging.handlers` module, |
| 871 | supports buffering of logging records in memory, periodically flushing them to a |
| 872 | :dfn:`target` handler. Flushing occurs whenever the buffer is full, or when an |
| 873 | event of a certain severity or greater is seen. |
| 874 | |
| 875 | :class:`MemoryHandler` is a subclass of the more general |
| 876 | :class:`BufferingHandler`, which is an abstract class. This buffers logging |
| 877 | records in memory. Whenever each record is added to the buffer, a check is made |
| 878 | by calling :meth:`shouldFlush` to see if the buffer should be flushed. If it |
| Vinay Sajip | 8ece80f | 2012-03-26 17:09:58 +0100 | [diff] [blame] | 879 | should, then :meth:`flush` is expected to do the flushing. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 880 | |
| 881 | |
| 882 | .. class:: BufferingHandler(capacity) |
| 883 | |
| Vinay Sajip | 84de34e | 2019-07-01 12:41:21 +0100 | [diff] [blame] | 884 | Initializes the handler with a buffer of the specified capacity. Here, |
| 885 | *capacity* means the number of logging records buffered. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 886 | |
| 887 | |
| 888 | .. method:: emit(record) |
| 889 | |
| Serhiy Storchaka | 138ccbb | 2019-11-12 16:57:03 +0200 | [diff] [blame] | 890 | Append the record to the buffer. If :meth:`shouldFlush` returns true, |
| 891 | call :meth:`flush` to process the buffer. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 892 | |
| 893 | |
| 894 | .. method:: flush() |
| 895 | |
| 896 | You can override this to implement custom flushing behavior. This version |
| 897 | just zaps the buffer to empty. |
| 898 | |
| 899 | |
| 900 | .. method:: shouldFlush(record) |
| 901 | |
| Serhiy Storchaka | 138ccbb | 2019-11-12 16:57:03 +0200 | [diff] [blame] | 902 | Return ``True`` if the buffer is up to capacity. This method can be |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 903 | overridden to implement custom flushing strategies. |
| 904 | |
| 905 | |
| Vinay Sajip | cccf606 | 2016-07-22 16:27:31 +0100 | [diff] [blame] | 906 | .. class:: MemoryHandler(capacity, flushLevel=ERROR, target=None, flushOnClose=True) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 907 | |
| 908 | Returns a new instance of the :class:`MemoryHandler` class. The instance is |
| Vinay Sajip | 84de34e | 2019-07-01 12:41:21 +0100 | [diff] [blame] | 909 | initialized with a buffer size of *capacity* (number of records buffered). |
| 910 | If *flushLevel* is not specified, :const:`ERROR` is used. If no *target* is |
| 911 | specified, the target will need to be set using :meth:`setTarget` before this |
| 912 | handler does anything useful. If *flushOnClose* is specified as ``False``, |
| 913 | then the buffer is *not* flushed when the handler is closed. If not specified |
| 914 | or specified as ``True``, the previous behaviour of flushing the buffer will |
| 915 | occur when the handler is closed. |
| Vinay Sajip | cccf606 | 2016-07-22 16:27:31 +0100 | [diff] [blame] | 916 | |
| 917 | .. versionchanged:: 3.6 |
| 918 | The *flushOnClose* parameter was added. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 919 | |
| 920 | |
| 921 | .. method:: close() |
| 922 | |
| Ezio Melotti | 226231c | 2012-01-18 05:40:00 +0200 | [diff] [blame] | 923 | Calls :meth:`flush`, sets the target to ``None`` and clears the |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 924 | buffer. |
| 925 | |
| 926 | |
| 927 | .. method:: flush() |
| 928 | |
| 929 | For a :class:`MemoryHandler`, flushing means just sending the buffered |
| 930 | records to the target, if there is one. The buffer is also cleared when |
| 931 | this happens. Override if you want different behavior. |
| 932 | |
| 933 | |
| 934 | .. method:: setTarget(target) |
| 935 | |
| 936 | Sets the target handler for this handler. |
| 937 | |
| 938 | |
| 939 | .. method:: shouldFlush(record) |
| 940 | |
| 941 | Checks for buffer full or a record at the *flushLevel* or higher. |
| 942 | |
| 943 | |
| 944 | .. _http-handler: |
| 945 | |
| 946 | HTTPHandler |
| 947 | ^^^^^^^^^^^ |
| 948 | |
| 949 | The :class:`HTTPHandler` class, located in the :mod:`logging.handlers` module, |
| Miss Islington (bot) | 6fc1efa | 2021-07-26 15:34:32 -0700 | [diff] [blame] | 950 | supports sending logging messages to a web server, using either ``GET`` or |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 951 | ``POST`` semantics. |
| 952 | |
| 953 | |
| Benjamin Peterson | 43052a1 | 2014-11-23 20:36:44 -0600 | [diff] [blame] | 954 | .. class:: HTTPHandler(host, url, method='GET', secure=False, credentials=None, context=None) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 955 | |
| 956 | Returns a new instance of the :class:`HTTPHandler` class. The *host* can be |
| Benjamin Peterson | 43052a1 | 2014-11-23 20:36:44 -0600 | [diff] [blame] | 957 | of the form ``host:port``, should you need to use a specific port number. If |
| 958 | no *method* is specified, ``GET`` is used. If *secure* is true, a HTTPS |
| 959 | connection will be used. The *context* parameter may be set to a |
| 960 | :class:`ssl.SSLContext` instance to configure the SSL settings used for the |
| 961 | HTTPS connection. If *credentials* is specified, it should be a 2-tuple |
| 962 | consisting of userid and password, which will be placed in a HTTP |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 963 | 'Authorization' header using Basic authentication. If you specify |
| 964 | credentials, you should also specify secure=True so that your userid and |
| 965 | password are not passed in cleartext across the wire. |
| 966 | |
| Benjamin Peterson | a90e92d | 2014-11-23 20:38:37 -0600 | [diff] [blame] | 967 | .. versionchanged:: 3.5 |
| Benjamin Peterson | 43052a1 | 2014-11-23 20:36:44 -0600 | [diff] [blame] | 968 | The *context* parameter was added. |
| 969 | |
| Vinay Sajip | c673a9a | 2014-05-30 18:59:27 +0100 | [diff] [blame] | 970 | .. method:: mapLogRecord(record) |
| 971 | |
| 972 | Provides a dictionary, based on ``record``, which is to be URL-encoded |
| 973 | and sent to the web server. The default implementation just returns |
| 974 | ``record.__dict__``. This method can be overridden if e.g. only a |
| 975 | subset of :class:`~logging.LogRecord` is to be sent to the web server, or |
| 976 | if more specific customization of what's sent to the server is required. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 977 | |
| 978 | .. method:: emit(record) |
| 979 | |
| Miss Islington (bot) | 6fc1efa | 2021-07-26 15:34:32 -0700 | [diff] [blame] | 980 | Sends the record to the web server as a URL-encoded dictionary. The |
| Vinay Sajip | c673a9a | 2014-05-30 18:59:27 +0100 | [diff] [blame] | 981 | :meth:`mapLogRecord` method is used to convert the record to the |
| 982 | dictionary to be sent. |
| 983 | |
| Miss Islington (bot) | 6fc1efa | 2021-07-26 15:34:32 -0700 | [diff] [blame] | 984 | .. note:: Since preparing a record for sending it to a web server is not |
| Vinay Sajip | c673a9a | 2014-05-30 18:59:27 +0100 | [diff] [blame] | 985 | the same as a generic formatting operation, using |
| 986 | :meth:`~logging.Handler.setFormatter` to specify a |
| 987 | :class:`~logging.Formatter` for a :class:`HTTPHandler` has no effect. |
| 988 | Instead of calling :meth:`~logging.Handler.format`, this handler calls |
| 989 | :meth:`mapLogRecord` and then :func:`urllib.parse.urlencode` to encode the |
| Miss Islington (bot) | 6fc1efa | 2021-07-26 15:34:32 -0700 | [diff] [blame] | 990 | dictionary in a form suitable for sending to a web server. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 991 | |
| 992 | |
| 993 | .. _queue-handler: |
| 994 | |
| 995 | |
| 996 | QueueHandler |
| 997 | ^^^^^^^^^^^^ |
| 998 | |
| 999 | .. versionadded:: 3.2 |
| 1000 | |
| 1001 | The :class:`QueueHandler` class, located in the :mod:`logging.handlers` module, |
| 1002 | supports sending logging messages to a queue, such as those implemented in the |
| 1003 | :mod:`queue` or :mod:`multiprocessing` modules. |
| 1004 | |
| 1005 | Along with the :class:`QueueListener` class, :class:`QueueHandler` can be used |
| 1006 | to let handlers do their work on a separate thread from the one which does the |
| Miss Islington (bot) | 6fc1efa | 2021-07-26 15:34:32 -0700 | [diff] [blame] | 1007 | logging. This is important in web applications and also other service |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1008 | applications where threads servicing clients need to respond as quickly as |
| 1009 | possible, while any potentially slow operations (such as sending an email via |
| 1010 | :class:`SMTPHandler`) are done on a separate thread. |
| 1011 | |
| 1012 | .. class:: QueueHandler(queue) |
| 1013 | |
| 1014 | Returns a new instance of the :class:`QueueHandler` class. The instance is |
| Vinay Sajip | e6b64b7 | 2019-07-01 18:45:07 +0100 | [diff] [blame] | 1015 | initialized with the queue to send messages to. The *queue* can be any |
| 1016 | queue-like object; it's used as-is by the :meth:`enqueue` method, which |
| 1017 | needs to know how to send messages to it. The queue is not *required* to |
| 1018 | have the task tracking API, which means that you can use |
| 1019 | :class:`~queue.SimpleQueue` instances for *queue*. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1020 | |
| 1021 | |
| 1022 | .. method:: emit(record) |
| 1023 | |
| Vinay Sajip | 0f4e813 | 2019-07-01 20:45:01 +0100 | [diff] [blame] | 1024 | Enqueues the result of preparing the LogRecord. Should an exception |
| 1025 | occur (e.g. because a bounded queue has filled up), the |
| 1026 | :meth:`~logging.Handler.handleError` method is called to handle the |
| 1027 | error. This can result in the record silently being dropped (if |
| 1028 | :attr:`logging.raiseExceptions` is ``False``) or a message printed to |
| 1029 | ``sys.stderr`` (if :attr:`logging.raiseExceptions` is ``True``). |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1030 | |
| 1031 | .. method:: prepare(record) |
| 1032 | |
| 1033 | Prepares a record for queuing. The object returned by this |
| 1034 | method is enqueued. |
| 1035 | |
| Cheryl Sabella | d345bb4 | 2018-09-25 19:00:08 -0400 | [diff] [blame] | 1036 | The base implementation formats the record to merge the message, |
| 1037 | arguments, and exception information, if present. It also |
| 1038 | removes unpickleable items from the record in-place. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1039 | |
| 1040 | You might want to override this method if you want to convert |
| 1041 | the record to a dict or JSON string, or send a modified copy |
| 1042 | of the record while leaving the original intact. |
| 1043 | |
| 1044 | .. method:: enqueue(record) |
| 1045 | |
| 1046 | Enqueues the record on the queue using ``put_nowait()``; you may |
| 1047 | want to override this if you want to use blocking behaviour, or a |
| Vinay Sajip | 9c10d6b | 2013-11-15 20:58:13 +0000 | [diff] [blame] | 1048 | timeout, or a customized queue implementation. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1049 | |
| 1050 | |
| 1051 | |
| Éric Araujo | 5eada94 | 2011-08-19 00:41:23 +0200 | [diff] [blame] | 1052 | .. _queue-listener: |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1053 | |
| 1054 | QueueListener |
| 1055 | ^^^^^^^^^^^^^ |
| 1056 | |
| 1057 | .. versionadded:: 3.2 |
| 1058 | |
| 1059 | The :class:`QueueListener` class, located in the :mod:`logging.handlers` |
| 1060 | module, supports receiving logging messages from a queue, such as those |
| 1061 | implemented in the :mod:`queue` or :mod:`multiprocessing` modules. The |
| 1062 | messages are received from a queue in an internal thread and passed, on |
| 1063 | the same thread, to one or more handlers for processing. While |
| 1064 | :class:`QueueListener` is not itself a handler, it is documented here |
| 1065 | because it works hand-in-hand with :class:`QueueHandler`. |
| 1066 | |
| 1067 | Along with the :class:`QueueHandler` class, :class:`QueueListener` can be used |
| 1068 | to let handlers do their work on a separate thread from the one which does the |
| Miss Islington (bot) | 6fc1efa | 2021-07-26 15:34:32 -0700 | [diff] [blame] | 1069 | logging. This is important in web applications and also other service |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1070 | applications where threads servicing clients need to respond as quickly as |
| 1071 | possible, while any potentially slow operations (such as sending an email via |
| 1072 | :class:`SMTPHandler`) are done on a separate thread. |
| 1073 | |
| Vinay Sajip | 365701a | 2015-02-09 19:49:00 +0000 | [diff] [blame] | 1074 | .. class:: QueueListener(queue, *handlers, respect_handler_level=False) |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1075 | |
| 1076 | Returns a new instance of the :class:`QueueListener` class. The instance is |
| 1077 | initialized with the queue to send messages to and a list of handlers which |
| Martin Panter | 8f13783 | 2017-01-14 08:24:20 +0000 | [diff] [blame] | 1078 | will handle entries placed on the queue. The queue can be any queue-like |
| 1079 | object; it's passed as-is to the :meth:`dequeue` method, which needs |
| Vinay Sajip | e6b64b7 | 2019-07-01 18:45:07 +0100 | [diff] [blame] | 1080 | to know how to get messages from it. The queue is not *required* to have the |
| 1081 | task tracking API (though it's used if available), which means that you can |
| 1082 | use :class:`~queue.SimpleQueue` instances for *queue*. |
| 1083 | |
| 1084 | If ``respect_handler_level`` is ``True``, a handler's level is respected |
| 1085 | (compared with the level for the message) when deciding whether to pass |
| 1086 | messages to that handler; otherwise, the behaviour is as in previous Python |
| 1087 | versions - to always pass each message to each handler. |
| Vinay Sajip | 365701a | 2015-02-09 19:49:00 +0000 | [diff] [blame] | 1088 | |
| 1089 | .. versionchanged:: 3.5 |
| wwuck | efd5741 | 2019-09-11 16:44:37 +1000 | [diff] [blame] | 1090 | The ``respect_handler_level`` argument was added. |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1091 | |
| 1092 | .. method:: dequeue(block) |
| 1093 | |
| 1094 | Dequeues a record and return it, optionally blocking. |
| 1095 | |
| 1096 | The base implementation uses ``get()``. You may want to override this |
| 1097 | method if you want to use timeouts or work with custom queue |
| 1098 | implementations. |
| 1099 | |
| 1100 | .. method:: prepare(record) |
| 1101 | |
| 1102 | Prepare a record for handling. |
| 1103 | |
| 1104 | This implementation just returns the passed-in record. You may want to |
| 1105 | override this method if you need to do any custom marshalling or |
| 1106 | manipulation of the record before passing it to the handlers. |
| 1107 | |
| 1108 | .. method:: handle(record) |
| 1109 | |
| 1110 | Handle a record. |
| 1111 | |
| 1112 | This just loops through the handlers offering them the record |
| 1113 | to handle. The actual object passed to the handlers is that which |
| 1114 | is returned from :meth:`prepare`. |
| 1115 | |
| 1116 | .. method:: start() |
| 1117 | |
| 1118 | Starts the listener. |
| 1119 | |
| 1120 | This starts up a background thread to monitor the queue for |
| 1121 | LogRecords to process. |
| 1122 | |
| 1123 | .. method:: stop() |
| 1124 | |
| 1125 | Stops the listener. |
| 1126 | |
| 1127 | This asks the thread to terminate, and then waits for it to do so. |
| 1128 | Note that if you don't call this before your application exits, there |
| 1129 | may be some records still left on the queue, which won't be processed. |
| 1130 | |
| Vinay Sajip | a29a9dd | 2011-02-25 16:05:26 +0000 | [diff] [blame] | 1131 | .. method:: enqueue_sentinel() |
| 1132 | |
| 1133 | Writes a sentinel to the queue to tell the listener to quit. This |
| 1134 | implementation uses ``put_nowait()``. You may want to override this |
| 1135 | method if you want to use timeouts or work with custom queue |
| 1136 | implementations. |
| 1137 | |
| 1138 | .. versionadded:: 3.3 |
| 1139 | |
| Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame] | 1140 | |
| 1141 | .. seealso:: |
| 1142 | |
| 1143 | Module :mod:`logging` |
| 1144 | API reference for the logging module. |
| 1145 | |
| 1146 | Module :mod:`logging.config` |
| 1147 | Configuration API for the logging module. |
| 1148 | |
| 1149 | |