Vinay Sajip | c63619b | 2010-12-19 12:56:57 +0000 | [diff] [blame^] | 1 | ============= |
| 2 | Logging HOWTO |
| 3 | ============= |
| 4 | |
| 5 | :Author: Vinay Sajip <vinay_sajip at red-dove dot com> |
| 6 | |
| 7 | .. Contents:: |
| 8 | |
| 9 | .. _logging-basic-tutorial: |
| 10 | |
| 11 | .. currentmodule:: logging |
| 12 | |
| 13 | Basic Logging Tutorial |
| 14 | ---------------------- |
| 15 | |
| 16 | Logging is a means of tracking events that happen when some software runs. The |
| 17 | software's developer adds logging calls to their code to indicate that certain |
| 18 | events have occurred. An event is described by a descriptive message which can |
| 19 | optionally contain variable data (i.e. data that is potentially different for |
| 20 | each occurrence of the event). Events also have an importance which the |
| 21 | developer ascribes to the event; the importance can also be called the *level* |
| 22 | or *severity*. |
| 23 | |
| 24 | When to use logging |
| 25 | ^^^^^^^^^^^^^^^^^^^ |
| 26 | |
| 27 | Logging provides a set of convenience functions for simple logging usage. These |
| 28 | are :func:`debug`, :func:`info`, :func:`warning`, :func:`error` and |
| 29 | :func:`critical`. To determine when to use logging, see the table below, which |
| 30 | states, for each of a set of common tasks, the best tool to use for it. |
| 31 | |
| 32 | +-------------------------------------+--------------------------------------+ |
| 33 | | Task you want to perform | The best tool for the task | |
| 34 | +=====================================+======================================+ |
| 35 | | Display console output for ordinary | :func:`print` | |
| 36 | | usage of a command line script or | | |
| 37 | | program | | |
| 38 | +-------------------------------------+--------------------------------------+ |
| 39 | | Report events that occur during | :func:`logging.info` (or | |
| 40 | | normal operation of a program (e.g. | :func:`logging.debug` for very | |
| 41 | | for status monitoring or fault | detailed output for diagnostic | |
| 42 | | investigation) | purposes) | |
| 43 | +-------------------------------------+--------------------------------------+ |
| 44 | | Issue a warning regarding a | :func:`warnings.warn` in library | |
| 45 | | particular runtime event | code if the issue is avoidable and | |
| 46 | | | the client application should be | |
| 47 | | | modified to eliminate the warning | |
| 48 | | | | |
| 49 | | | :func:`logging.warning` if there is | |
| 50 | | | nothing the client application can do| |
| 51 | | | about the situation, but the event | |
| 52 | | | should still be noted | |
| 53 | +-------------------------------------+--------------------------------------+ |
| 54 | | Report an error regarding a | Raise an exception | |
| 55 | | particular runtime event | | |
| 56 | +-------------------------------------+--------------------------------------+ |
| 57 | | Report suppression of an error | :func:`logging.error`, | |
| 58 | | without raising an exception (e.g. | :func:`logging.exception` or | |
| 59 | | error handler in a long-running | :func:`logging.critical` as | |
| 60 | | server process) | appropriate for the specific error | |
| 61 | | | and application domain | |
| 62 | +-------------------------------------+--------------------------------------+ |
| 63 | |
| 64 | The logging functions are named after the level or severity of the events |
| 65 | they are used to track. The standard levels and their applicability are |
| 66 | described below (in increasing order of severity): |
| 67 | |
| 68 | +--------------+---------------------------------------------+ |
| 69 | | Level | When it's used | |
| 70 | +==============+=============================================+ |
| 71 | | ``DEBUG`` | Detailed information, typically of interest | |
| 72 | | | only when diagnosing problems. | |
| 73 | +--------------+---------------------------------------------+ |
| 74 | | ``INFO`` | Confirmation that things are working as | |
| 75 | | | expected. | |
| 76 | +--------------+---------------------------------------------+ |
| 77 | | ``WARNING`` | An indication that something unexpected | |
| 78 | | | happened, or indicative of some problem in | |
| 79 | | | the near future (e.g. 'disk space low'). | |
| 80 | | | The software is still working as expected. | |
| 81 | +--------------+---------------------------------------------+ |
| 82 | | ``ERROR`` | Due to a more serious problem, the software | |
| 83 | | | has not been able to perform some function. | |
| 84 | +--------------+---------------------------------------------+ |
| 85 | | ``CRITICAL`` | A serious error, indicating that the program| |
| 86 | | | itself may be unable to continue running. | |
| 87 | +--------------+---------------------------------------------+ |
| 88 | |
| 89 | The default level is ``WARNING``, which means that only events of this level |
| 90 | and above will be tracked, unless the logging package is configured to do |
| 91 | otherwise. |
| 92 | |
| 93 | Events that are tracked can be handled in different ways. The simplest way of |
| 94 | handling tracked events is to print them to the console. Another common way |
| 95 | is to write them to a disk file. |
| 96 | |
| 97 | |
| 98 | .. _howto-minimal-example: |
| 99 | |
| 100 | A simple example |
| 101 | ^^^^^^^^^^^^^^^^ |
| 102 | |
| 103 | A very simple example is:: |
| 104 | |
| 105 | import logging |
| 106 | logging.warning('Watch out!') # will print a message to the console |
| 107 | logging.info('I told you so') # will not print anything |
| 108 | |
| 109 | If you type these lines into a script and run it, you'll see:: |
| 110 | |
| 111 | WARNING:root:Watch out! |
| 112 | |
| 113 | printed out on the console. The ``INFO`` message doesn't appear because the |
| 114 | default level is ``WARNING``. The printed message includes the indication of |
| 115 | the level and the description of the event provided in the logging call, i.e. |
| 116 | 'Watch out!'. Don't worry about the 'root' part for now: it will be explained |
| 117 | later. The actual output can be formatted quite flexibly if you need that; |
| 118 | formatting options will also be explained later. |
| 119 | |
| 120 | |
| 121 | Logging to a file |
| 122 | ^^^^^^^^^^^^^^^^^ |
| 123 | |
| 124 | A very common situation is that of recording logging events in a file, so let's |
| 125 | look at that next:: |
| 126 | |
| 127 | import logging |
| 128 | logging.basicConfig(filename='example.log',level=logging.DEBUG) |
| 129 | logging.debug('This message should go to the log file') |
| 130 | logging.info('So should this') |
| 131 | logging.warning('And this, too') |
| 132 | |
| 133 | And now if we open the file and look at what we have, we should find the log |
| 134 | messages:: |
| 135 | |
| 136 | DEBUG:root:This message should go to the log file |
| 137 | INFO:root:So should this |
| 138 | WARNING:root:And this, too |
| 139 | |
| 140 | This example also shows how you can set the logging level which acts as the |
| 141 | threshold for tracking. In this case, because we set the threshold to |
| 142 | ``DEBUG``, all of the messages were printed. |
| 143 | |
| 144 | If you want to set the logging level from a command-line option such as:: |
| 145 | |
| 146 | --log=INFO |
| 147 | |
| 148 | and you have the value of the parameter passed for ``--log`` in some variable |
| 149 | *loglevel*, you can use:: |
| 150 | |
| 151 | getattr(logging, loglevel.upper()) |
| 152 | |
| 153 | to get the value which you'll pass to :func:`basicConfig` via the *level* |
| 154 | argument. You may want to error check any user input value, perhaps as in the |
| 155 | following example:: |
| 156 | |
| 157 | # assuming loglevel is bound to the string value obtained from the |
| 158 | # command line argument. Convert to upper case to allow the user to |
| 159 | # specify --log=DEBUG or --log=debug |
| 160 | numeric_level = getattr(logging, loglevel.upper(), None) |
| 161 | if not isinstance(numeric_level, int): |
| 162 | raise ValueError('Invalid log level: %s' % loglevel) |
| 163 | logging.basicConfig(level=numeric_level, ...) |
| 164 | |
| 165 | The call to :func:`basicConfig` should come *before* any calls to :func:`debug`, |
| 166 | :func:`info` etc. As it's intended as a one-off simple configuration facility, |
| 167 | only the first call will actually do anything: subsequent calls are effectively |
| 168 | no-ops. |
| 169 | |
| 170 | If you run the above script several times, the messages from successive runs |
| 171 | are appended to the file *example.log*. If you want each run to start afresh, |
| 172 | not remembering the messages from earlier runs, you can specify the *filemode* |
| 173 | argument, by changing the call in the above example to:: |
| 174 | |
| 175 | logging.basicConfig(filename='example.log', filemode='w', level=logging.DEBUG) |
| 176 | |
| 177 | The output will be the same as before, but the log file is no longer appended |
| 178 | to, so the messages from earlier runs are lost. |
| 179 | |
| 180 | |
| 181 | Logging from multiple modules |
| 182 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 183 | |
| 184 | If your program consists of multiple modules, here's an example of how you |
| 185 | could organize logging in it:: |
| 186 | |
| 187 | # myapp.py |
| 188 | import logging |
| 189 | import mylib |
| 190 | |
| 191 | def main(): |
| 192 | logging.basicConfig(filename='myapp.log', level=logging.INFO) |
| 193 | logging.info('Started') |
| 194 | mylib.do_something() |
| 195 | logging.info('Finished') |
| 196 | |
| 197 | if __name__ == '__main__': |
| 198 | main() |
| 199 | |
| 200 | :: |
| 201 | |
| 202 | # mylib.py |
| 203 | import logging |
| 204 | |
| 205 | def do_something(): |
| 206 | logging.info('Doing something') |
| 207 | |
| 208 | If you run *myapp.py*, you should see this in *myapp.log*:: |
| 209 | |
| 210 | INFO:root:Started |
| 211 | INFO:root:Doing something |
| 212 | INFO:root:Finished |
| 213 | |
| 214 | which is hopefully what you were expecting to see. You can generalize this to |
| 215 | multiple modules, using the pattern in *mylib.py*. Note that for this simple |
| 216 | usage pattern, you won't know, by looking in the log file, *where* in your |
| 217 | application your messages came from, apart from looking at the event |
| 218 | description. If you want to track the location of your messages, you'll need |
| 219 | to refer to the documentation beyond the tutorial level - see |
| 220 | :ref:`advanced-logging-tutorial`. |
| 221 | |
| 222 | |
| 223 | Logging variable data |
| 224 | ^^^^^^^^^^^^^^^^^^^^^ |
| 225 | |
| 226 | To log variable data, use a format string for the event description message and |
| 227 | append the variable data as arguments. For example:: |
| 228 | |
| 229 | import logging |
| 230 | logging.warning('%s before you %s', 'Look', 'leap!') |
| 231 | |
| 232 | will display:: |
| 233 | |
| 234 | WARNING:root:Look before you leap! |
| 235 | |
| 236 | As you can see, merging of variable data into the event description message |
| 237 | uses the old, %-style of string formatting. This is for backwards |
| 238 | compatibility: the logging package pre-dates newer formatting options such as |
| 239 | :meth:`str.format` and :class:`string.Template`. These newer formatting |
| 240 | options *are* supported, but exploring them is outside the scope of this |
| 241 | tutorial. |
| 242 | |
| 243 | |
| 244 | Changing the format of displayed messages |
| 245 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 246 | |
| 247 | To change the format which is used to display messages, you need to |
| 248 | specify the format you want to use:: |
| 249 | |
| 250 | import logging |
| 251 | logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) |
| 252 | logging.debug('This message should appear on the console') |
| 253 | logging.info('So should this') |
| 254 | logging.warning('And this, too') |
| 255 | |
| 256 | which would print:: |
| 257 | |
| 258 | DEBUG:This message should appear on the console |
| 259 | INFO:So should this |
| 260 | WARNING:And this, too |
| 261 | |
| 262 | Notice that the 'root' which appeared in earlier examples has disappeared. For |
| 263 | a full set of things that can appear in format strings, you can refer to the |
| 264 | documentation for :ref:`logrecord-attributes`, but for simple usage, you just |
| 265 | need the *levelname* (severity), *message* (event description, including |
| 266 | variable data) and perhaps to display when the event occurred. This is |
| 267 | described in the next section. |
| 268 | |
| 269 | |
| 270 | Displaying the date/time in messages |
| 271 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 272 | |
| 273 | To display the date and time of an event, you would place '%(asctime)s' in |
| 274 | your format string:: |
| 275 | |
| 276 | import logging |
| 277 | logging.basicConfig(format='%(asctime)s %(message)s') |
| 278 | logging.warning('is when this event was logged.') |
| 279 | |
| 280 | which should print something like this:: |
| 281 | |
| 282 | 2010-12-12 11:41:42,612 is when this event was logged. |
| 283 | |
| 284 | The default format for date/time display (shown above) is ISO8601. If you need |
| 285 | more control over the formatting of the date/time, provide a *datefmt* |
| 286 | argument to ``basicConfig``, as in this example:: |
| 287 | |
| 288 | import logging |
| 289 | logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') |
| 290 | logging.warning('is when this event was logged.') |
| 291 | |
| 292 | which would display something like this:: |
| 293 | |
| 294 | 12/12/2010 11:46:36 AM is when this event was logged. |
| 295 | |
| 296 | The format of the *datefmt* argument is the same as supported by |
| 297 | :func:`time.strftime`. |
| 298 | |
| 299 | |
| 300 | Next Steps |
| 301 | ^^^^^^^^^^ |
| 302 | |
| 303 | That concludes the basic tutorial. It should be enough to get you up and |
| 304 | running with logging. There's a lot more that the logging package offers, but |
| 305 | to get the best out of it, you'll need to invest a little more of your time in |
| 306 | reading the following sections. If you're ready for that, grab some of your |
| 307 | favourite beverage and carry on. |
| 308 | |
| 309 | If your logging needs are simple, then use the above examples to incorporate |
| 310 | logging into your own scripts, and if you run into problems or don't |
| 311 | understand something, please post a question on the comp.lang.python Usenet |
| 312 | group (available at http://groups.google.com/group/comp.lang.python) and you |
| 313 | should receive help before too long. |
| 314 | |
| 315 | Still here? There's no need to read the whole of the logging documentation in |
| 316 | linear fashion, top to bottom (there's quite a lot of it still to come). You |
| 317 | can carry on reading the next few sections, which provide a slightly more |
| 318 | advanced/in-depth tutorial than the basic one above. After that, you can |
| 319 | take a look at the :ref:`logging-cookbook`. |
| 320 | |
| 321 | .. _logging-advanced-tutorial: |
| 322 | |
| 323 | |
| 324 | Advanced Logging Tutorial |
| 325 | ------------------------- |
| 326 | |
| 327 | The logging library takes a modular approach and offers several categories |
| 328 | of components: loggers, handlers, filters, and formatters. |
| 329 | |
| 330 | * Loggers expose the interface that application code directly uses. |
| 331 | * Handlers send the log records (created by loggers) to the appropriate |
| 332 | destination. |
| 333 | * Filters provide a finer grained facility for determining which log records |
| 334 | to output. |
| 335 | * Formatters specify the layout of log records in the final output. |
| 336 | |
| 337 | Logging is performed by calling methods on instances of the :class:`Logger` |
| 338 | class (hereafter called :dfn:`loggers`). Each instance has a name, and they are |
| 339 | conceptually arranged in a namespace hierarchy using dots (periods) as |
| 340 | separators. For example, a logger named 'scan' is the parent of loggers |
| 341 | 'scan.text', 'scan.html' and 'scan.pdf'. Logger names can be anything you want, |
| 342 | and indicate the area of an application in which a logged message originates. |
| 343 | |
| 344 | A good convention to use when naming loggers is to use a module-level logger, |
| 345 | in each module which uses logging, named as follows:: |
| 346 | |
| 347 | logger = logging.getLogger(__name__) |
| 348 | |
| 349 | This means that logger names track the package/module hierarchy, and it's |
| 350 | intuitively obvious where events are logged just from the logger name. |
| 351 | |
| 352 | The root of the hierarchy of loggers is called the root logger. That's the |
| 353 | logger used by the functions :func:`debug`, :func:`info`, :func:`warning`, |
| 354 | :func:`error` and :func:`critical`, which just call the same-named method of |
| 355 | the root logger. The functions and the methods have the same signatures. The |
| 356 | root logger's name is printed as 'root' in the logged output. |
| 357 | |
| 358 | It is, of course, possible to log messages to different destinations. Support |
| 359 | is included in the package for writing log messages to files, HTTP GET/POST |
| 360 | locations, email via SMTP, generic sockets, queues, or OS-specific logging |
| 361 | mechanisms such as syslog or the Windows NT event log. Destinations are served |
| 362 | by :dfn:`handler` classes. You can create your own log destination class if |
| 363 | you have special requirements not met by any of the built-in handler classes. |
| 364 | |
| 365 | By default, no destination is set for any logging messages. You can specify |
| 366 | a destination (such as console or file) by using :func:`basicConfig` as in the |
| 367 | tutorial examples. If you call the functions :func:`debug`, :func:`info`, |
| 368 | :func:`warning`, :func:`error` and :func:`critical`, they will check to see |
| 369 | if no destination is set; and if one is not set, they will set a destination |
| 370 | of the console (``sys.stderr``) and a default format for the displayed |
| 371 | message before delegating to the root logger to do the actual message output. |
| 372 | |
| 373 | The default format set by :func:`basicConfig` for messages is:: |
| 374 | |
| 375 | severity:logger name:message |
| 376 | |
| 377 | You can change this by passing a format string to :func:`basicConfig` with the |
| 378 | *format* keyword argument. For all options regarding how a format string is |
| 379 | constructed, see :ref:`formatter-objects`. |
| 380 | |
| 381 | |
| 382 | Loggers |
| 383 | ^^^^^^^ |
| 384 | |
| 385 | :class:`Logger` objects have a threefold job. First, they expose several |
| 386 | methods to application code so that applications can log messages at runtime. |
| 387 | Second, logger objects determine which log messages to act upon based upon |
| 388 | severity (the default filtering facility) or filter objects. Third, logger |
| 389 | objects pass along relevant log messages to all interested log handlers. |
| 390 | |
| 391 | The most widely used methods on logger objects fall into two categories: |
| 392 | configuration and message sending. |
| 393 | |
| 394 | These are the most common configuration methods: |
| 395 | |
| 396 | * :meth:`Logger.setLevel` specifies the lowest-severity log message a logger |
| 397 | will handle, where debug is the lowest built-in severity level and critical |
| 398 | is the highest built-in severity. For example, if the severity level is |
| 399 | INFO, the logger will handle only INFO, WARNING, ERROR, and CRITICAL messages |
| 400 | and will ignore DEBUG messages. |
| 401 | |
| 402 | * :meth:`Logger.addHandler` and :meth:`Logger.removeHandler` add and remove |
| 403 | handler objects from the logger object. Handlers are covered in more detail |
| 404 | in :ref:`handler-basic`. |
| 405 | |
| 406 | * :meth:`Logger.addFilter` and :meth:`Logger.removeFilter` add and remove filter |
| 407 | objects from the logger object. Filters are covered in more detail in |
| 408 | :ref:`filter`. |
| 409 | |
| 410 | You don't need to always call these methods on every logger you create. See the |
| 411 | last two paragraphs in this section. |
| 412 | |
| 413 | With the logger object configured, the following methods create log messages: |
| 414 | |
| 415 | * :meth:`Logger.debug`, :meth:`Logger.info`, :meth:`Logger.warning`, |
| 416 | :meth:`Logger.error`, and :meth:`Logger.critical` all create log records with |
| 417 | a message and a level that corresponds to their respective method names. The |
| 418 | message is actually a format string, which may contain the standard string |
| 419 | substitution syntax of :const:`%s`, :const:`%d`, :const:`%f`, and so on. The |
| 420 | rest of their arguments is a list of objects that correspond with the |
| 421 | substitution fields in the message. With regard to :const:`**kwargs`, the |
| 422 | logging methods care only about a keyword of :const:`exc_info` and use it to |
| 423 | determine whether to log exception information. |
| 424 | |
| 425 | * :meth:`Logger.exception` creates a log message similar to |
| 426 | :meth:`Logger.error`. The difference is that :meth:`Logger.exception` dumps a |
| 427 | stack trace along with it. Call this method only from an exception handler. |
| 428 | |
| 429 | * :meth:`Logger.log` takes a log level as an explicit argument. This is a |
| 430 | little more verbose for logging messages than using the log level convenience |
| 431 | methods listed above, but this is how to log at custom log levels. |
| 432 | |
| 433 | :func:`getLogger` returns a reference to a logger instance with the specified |
| 434 | name if it is provided, or ``root`` if not. The names are period-separated |
| 435 | hierarchical structures. Multiple calls to :func:`getLogger` with the same name |
| 436 | will return a reference to the same logger object. Loggers that are further |
| 437 | down in the hierarchical list are children of loggers higher up in the list. |
| 438 | For example, given a logger with a name of ``foo``, loggers with names of |
| 439 | ``foo.bar``, ``foo.bar.baz``, and ``foo.bam`` are all descendants of ``foo``. |
| 440 | |
| 441 | Loggers have a concept of *effective level*. If a level is not explicitly set |
| 442 | on a logger, the level of its parent is used instead as its effective level. |
| 443 | If the parent has no explicit level set, *its* parent is examined, and so on - |
| 444 | all ancestors are searched until an explicitly set level is found. The root |
| 445 | logger always has an explicit level set (``WARNING`` by default). When deciding |
| 446 | whether to process an event, the effective level of the logger is used to |
| 447 | determine whether the event is passed to the logger's handlers. |
| 448 | |
| 449 | Child loggers propagate messages up to the handlers associated with their |
| 450 | ancestor loggers. Because of this, it is unnecessary to define and configure |
| 451 | handlers for all the loggers an application uses. It is sufficient to |
| 452 | configure handlers for a top-level logger and create child loggers as needed. |
| 453 | (You can, however, turn off propagation by setting the *propagate* |
| 454 | attribute of a logger to *False*.) |
| 455 | |
| 456 | |
| 457 | .. _handler-basic: |
| 458 | |
| 459 | Handlers |
| 460 | ^^^^^^^^ |
| 461 | |
| 462 | :class:`Handler` objects are responsible for dispatching the appropriate log |
| 463 | messages (based on the log messages' severity) to the handler's specified |
| 464 | destination. Logger objects can add zero or more handler objects to themselves |
| 465 | with an :func:`addHandler` method. As an example scenario, an application may |
| 466 | want to send all log messages to a log file, all log messages of error or higher |
| 467 | to stdout, and all messages of critical to an email address. This scenario |
| 468 | requires three individual handlers where each handler is responsible for sending |
| 469 | messages of a specific severity to a specific location. |
| 470 | |
| 471 | The standard library includes quite a few handler types (see |
| 472 | :ref:`useful-handlers`); the tutorials use mainly :class:`StreamHandler` and |
| 473 | :class:`FileHandler` in its examples. |
| 474 | |
| 475 | There are very few methods in a handler for application developers to concern |
| 476 | themselves with. The only handler methods that seem relevant for application |
| 477 | developers who are using the built-in handler objects (that is, not creating |
| 478 | custom handlers) are the following configuration methods: |
| 479 | |
| 480 | * The :meth:`Handler.setLevel` method, just as in logger objects, specifies the |
| 481 | lowest severity that will be dispatched to the appropriate destination. Why |
| 482 | are there two :func:`setLevel` methods? The level set in the logger |
| 483 | determines which severity of messages it will pass to its handlers. The level |
| 484 | set in each handler determines which messages that handler will send on. |
| 485 | |
| 486 | * :func:`setFormatter` selects a Formatter object for this handler to use. |
| 487 | |
| 488 | * :func:`addFilter` and :func:`removeFilter` respectively configure and |
| 489 | deconfigure filter objects on handlers. |
| 490 | |
| 491 | Application code should not directly instantiate and use instances of |
| 492 | :class:`Handler`. Instead, the :class:`Handler` class is a base class that |
| 493 | defines the interface that all handlers should have and establishes some |
| 494 | default behavior that child classes can use (or override). |
| 495 | |
| 496 | |
| 497 | Formatters |
| 498 | ^^^^^^^^^^ |
| 499 | |
| 500 | Formatter objects configure the final order, structure, and contents of the log |
| 501 | message. Unlike the base :class:`logging.Handler` class, application code may |
| 502 | instantiate formatter classes, although you could likely subclass the formatter |
| 503 | if your application needs special behavior. The constructor takes three |
| 504 | optional arguments -- a message format string, a date format string and a style |
| 505 | indicator. |
| 506 | |
| 507 | .. method:: logging.Formatter.__init__(fmt=None, datefmt=None, style='%') |
| 508 | |
| 509 | If there is no message format string, the default is to use the |
| 510 | raw message. If there is no date format string, the default date format is:: |
| 511 | |
| 512 | %Y-%m-%d %H:%M:%S |
| 513 | |
| 514 | with the milliseconds tacked on at the end. The ``style`` is one of `%`, '{' |
| 515 | or '$'. If one of these is not specified, then '%' will be used. |
| 516 | |
| 517 | If the ``style`` is '%', the message format string uses |
| 518 | ``%(<dictionary key>)s`` styled string substitution; the possible keys are |
| 519 | documented in :ref:`logrecord-attributes`. If the style is '{', the message |
| 520 | format string is assumed to be compatible with :meth:`str.format` (using |
| 521 | keyword arguments), while if the style is '$' then the message format string |
| 522 | should conform to what is expected by :meth:`string.Template.substitute`. |
| 523 | |
| 524 | .. versionchanged:: 3.2 |
| 525 | Added the ``style`` parameter. |
| 526 | |
| 527 | The following message format string will log the time in a human-readable |
| 528 | format, the severity of the message, and the contents of the message, in that |
| 529 | order:: |
| 530 | |
| 531 | '%(asctime)s - %(levelname)s - %(message)s' |
| 532 | |
| 533 | Formatters use a user-configurable function to convert the creation time of a |
| 534 | record to a tuple. By default, :func:`time.localtime` is used; to change this |
| 535 | for a particular formatter instance, set the ``converter`` attribute of the |
| 536 | instance to a function with the same signature as :func:`time.localtime` or |
| 537 | :func:`time.gmtime`. To change it for all formatters, for example if you want |
| 538 | all logging times to be shown in GMT, set the ``converter`` attribute in the |
| 539 | Formatter class (to ``time.gmtime`` for GMT display). |
| 540 | |
| 541 | |
| 542 | Configuring Logging |
| 543 | ^^^^^^^^^^^^^^^^^^^ |
| 544 | |
| 545 | Programmers can configure logging in three ways: |
| 546 | |
| 547 | 1. Creating loggers, handlers, and formatters explicitly using Python |
| 548 | code that calls the configuration methods listed above. |
| 549 | 2. Creating a logging config file and reading it using the :func:`fileConfig` |
| 550 | function. |
| 551 | 3. Creating a dictionary of configuration information and passing it |
| 552 | to the :func:`dictConfig` function. |
| 553 | |
| 554 | For the reference documentation on the last two options, see :ref:`config-ref`. |
| 555 | The following example configures a very simple logger, a console handler, and |
| 556 | a simple formatter using Python code:: |
| 557 | |
| 558 | import logging |
| 559 | |
| 560 | # create logger |
| 561 | logger = logging.getLogger('simple_example') |
| 562 | logger.setLevel(logging.DEBUG) |
| 563 | |
| 564 | # create console handler and set level to debug |
| 565 | ch = logging.StreamHandler() |
| 566 | ch.setLevel(logging.DEBUG) |
| 567 | |
| 568 | # create formatter |
| 569 | formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') |
| 570 | |
| 571 | # add formatter to ch |
| 572 | ch.setFormatter(formatter) |
| 573 | |
| 574 | # add ch to logger |
| 575 | logger.addHandler(ch) |
| 576 | |
| 577 | # 'application' code |
| 578 | logger.debug('debug message') |
| 579 | logger.info('info message') |
| 580 | logger.warn('warn message') |
| 581 | logger.error('error message') |
| 582 | logger.critical('critical message') |
| 583 | |
| 584 | Running this module from the command line produces the following output:: |
| 585 | |
| 586 | $ python simple_logging_module.py |
| 587 | 2005-03-19 15:10:26,618 - simple_example - DEBUG - debug message |
| 588 | 2005-03-19 15:10:26,620 - simple_example - INFO - info message |
| 589 | 2005-03-19 15:10:26,695 - simple_example - WARNING - warn message |
| 590 | 2005-03-19 15:10:26,697 - simple_example - ERROR - error message |
| 591 | 2005-03-19 15:10:26,773 - simple_example - CRITICAL - critical message |
| 592 | |
| 593 | The following Python module creates a logger, handler, and formatter nearly |
| 594 | identical to those in the example listed above, with the only difference being |
| 595 | the names of the objects:: |
| 596 | |
| 597 | import logging |
| 598 | import logging.config |
| 599 | |
| 600 | logging.config.fileConfig('logging.conf') |
| 601 | |
| 602 | # create logger |
| 603 | logger = logging.getLogger('simpleExample') |
| 604 | |
| 605 | # 'application' code |
| 606 | logger.debug('debug message') |
| 607 | logger.info('info message') |
| 608 | logger.warn('warn message') |
| 609 | logger.error('error message') |
| 610 | logger.critical('critical message') |
| 611 | |
| 612 | Here is the logging.conf file:: |
| 613 | |
| 614 | [loggers] |
| 615 | keys=root,simpleExample |
| 616 | |
| 617 | [handlers] |
| 618 | keys=consoleHandler |
| 619 | |
| 620 | [formatters] |
| 621 | keys=simpleFormatter |
| 622 | |
| 623 | [logger_root] |
| 624 | level=DEBUG |
| 625 | handlers=consoleHandler |
| 626 | |
| 627 | [logger_simpleExample] |
| 628 | level=DEBUG |
| 629 | handlers=consoleHandler |
| 630 | qualname=simpleExample |
| 631 | propagate=0 |
| 632 | |
| 633 | [handler_consoleHandler] |
| 634 | class=StreamHandler |
| 635 | level=DEBUG |
| 636 | formatter=simpleFormatter |
| 637 | args=(sys.stdout,) |
| 638 | |
| 639 | [formatter_simpleFormatter] |
| 640 | format=%(asctime)s - %(name)s - %(levelname)s - %(message)s |
| 641 | datefmt= |
| 642 | |
| 643 | The output is nearly identical to that of the non-config-file-based example:: |
| 644 | |
| 645 | $ python simple_logging_config.py |
| 646 | 2005-03-19 15:38:55,977 - simpleExample - DEBUG - debug message |
| 647 | 2005-03-19 15:38:55,979 - simpleExample - INFO - info message |
| 648 | 2005-03-19 15:38:56,054 - simpleExample - WARNING - warn message |
| 649 | 2005-03-19 15:38:56,055 - simpleExample - ERROR - error message |
| 650 | 2005-03-19 15:38:56,130 - simpleExample - CRITICAL - critical message |
| 651 | |
| 652 | You can see that the config file approach has a few advantages over the Python |
| 653 | code approach, mainly separation of configuration and code and the ability of |
| 654 | noncoders to easily modify the logging properties. |
| 655 | |
| 656 | Note that the class names referenced in config files need to be either relative |
| 657 | to the logging module, or absolute values which can be resolved using normal |
| 658 | import mechanisms. Thus, you could use either |
| 659 | :class:`handlers.WatchedFileHandler` (relative to the logging module) or |
| 660 | ``mypackage.mymodule.MyHandler`` (for a class defined in package ``mypackage`` |
| 661 | and module ``mymodule``, where ``mypackage`` is available on the Python import |
| 662 | path). |
| 663 | |
| 664 | In Python 3.2, a new means of configuring logging has been introduced, using |
| 665 | dictionaries to hold configuration information. This provides a superset of the |
| 666 | functionality of the config-file-based approach outlined above, and is the |
| 667 | recommended configuration method for new applications and deployments. Because |
| 668 | a Python dictionary is used to hold configuration information, and since you |
| 669 | can populate that dictionary using different means, you have more options for |
| 670 | configuration. For example, you can use a configuration file in JSON format, |
| 671 | or, if you have access to YAML processing functionality, a file in YAML |
| 672 | format, to populate the configuration dictionary. Or, of course, you can |
| 673 | construct the dictionary in Python code, receive it in pickled form over a |
| 674 | socket, or use whatever approach makes sense for your application. |
| 675 | |
| 676 | Here's an example of the same configuration as above, in YAML format for |
| 677 | the new dictionary-based approach:: |
| 678 | |
| 679 | version: 1 |
| 680 | formatters: |
| 681 | simple: |
| 682 | format: format=%(asctime)s - %(name)s - %(levelname)s - %(message)s |
| 683 | handlers: |
| 684 | console: |
| 685 | class: logging.StreamHandler |
| 686 | level: DEBUG |
| 687 | formatter: simple |
| 688 | stream: ext://sys.stdout |
| 689 | loggers: |
| 690 | simpleExample: |
| 691 | level: DEBUG |
| 692 | handlers: [console] |
| 693 | propagate: no |
| 694 | root: |
| 695 | level: DEBUG |
| 696 | handlers: [console] |
| 697 | |
| 698 | For more information about logging using a dictionary, see |
| 699 | :ref:`logging-config-api`. |
| 700 | |
| 701 | What happens if no configuration is provided |
| 702 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 703 | |
| 704 | If no logging configuration is provided, it is possible to have a situation |
| 705 | where a logging event needs to be output, but no handlers can be found to |
| 706 | output the event. The behaviour of the logging package in these |
| 707 | circumstances is dependent on the Python version. |
| 708 | |
| 709 | For versions of Python prior to 3.2, the behaviour is as follows: |
| 710 | |
| 711 | * If *logging.raiseExceptions* is *False* (production mode), the event is |
| 712 | silently dropped. |
| 713 | |
| 714 | * If *logging.raiseExceptions* is *True* (development mode), a message |
| 715 | 'No handlers could be found for logger X.Y.Z' is printed once. |
| 716 | |
| 717 | In Python 3.2 and later, the behaviour is as follows: |
| 718 | |
| 719 | * The event is output using a 'handler of last resort', stored in |
| 720 | ``logging.lastResort``. This internal handler is not associated with any |
| 721 | logger, and acts like a :class:`StreamHandler` which writes the event |
| 722 | description message to the current value of ``sys.stderr`` (therefore |
| 723 | respecting any redirections which may be in effect). No formatting is |
| 724 | done on the message - just the bare event description message is printed. |
| 725 | The handler's level is set to ``WARNING``, so all events at this and |
| 726 | greater severities will be output. |
| 727 | |
| 728 | To obtain the pre-3.2 behaviour, ``logging.lastResort`` can be set to *None*. |
| 729 | |
| 730 | .. _library-config: |
| 731 | |
| 732 | Configuring Logging for a Library |
| 733 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 734 | |
| 735 | When developing a library which uses logging, you should take care to |
| 736 | document how the library uses logging - for example, the names of loggers |
| 737 | used. Some consideration also needs to be given to its logging configuration. |
| 738 | If the using application does not use logging, and library code makes logging |
| 739 | calls, then (as described in the previous section) events of severity |
| 740 | ``WARNING`` and greater will be printed to ``sys.stderr``. This is regarded as |
| 741 | the best default behaviour. |
| 742 | |
| 743 | If for some reason you *don't* want these messages printed in the absence of |
| 744 | any logging configuration, you can attach a do-nothing handler to the top-level |
| 745 | logger for your library. This avoids the message being printed, since a handler |
| 746 | will be always be found for the library's events: it just doesn't produce any |
| 747 | output. If the library user configures logging for application use, presumably |
| 748 | that configuration will add some handlers, and if levels are suitably |
| 749 | configured then logging calls made in library code will send output to those |
| 750 | handlers, as normal. |
| 751 | |
| 752 | A do-nothing handler is included in the logging package: :class:`NullHandler` |
| 753 | (since Python 3.1). An instance of this handler could be added to the top-level |
| 754 | logger of the logging namespace used by the library (*if* you want to prevent |
| 755 | your library's logged events being output to ``sys.stderr`` in the absence of |
| 756 | logging configuration). If all logging by a library *foo* is done using loggers |
| 757 | with names matching 'foo.x', 'foo.x.y', etc. then the code:: |
| 758 | |
| 759 | import logging |
| 760 | logging.getLogger('foo').addHandler(logging.NullHandler()) |
| 761 | |
| 762 | should have the desired effect. If an organisation produces a number of |
| 763 | libraries, then the logger name specified can be 'orgname.foo' rather than |
| 764 | just 'foo'. |
| 765 | |
| 766 | **PLEASE NOTE:** It is strongly advised that you *do not add any handlers other |
| 767 | than* :class:`NullHandler` *to your library's loggers*. This is because the |
| 768 | configuration of handlers is the prerogative of the application developer who |
| 769 | uses your library. The application developer knows their target audience and |
| 770 | what handlers are most appropriate for their application: if you add handlers |
| 771 | 'under the hood', you might well interfere with their ability to carry out |
| 772 | unit tests and deliver logs which suit their requirements. |
| 773 | |
| 774 | |
| 775 | Logging Levels |
| 776 | -------------- |
| 777 | |
| 778 | The numeric values of logging levels are given in the following table. These are |
| 779 | primarily of interest if you want to define your own levels, and need them to |
| 780 | have specific values relative to the predefined levels. If you define a level |
| 781 | with the same numeric value, it overwrites the predefined value; the predefined |
| 782 | name is lost. |
| 783 | |
| 784 | +--------------+---------------+ |
| 785 | | Level | Numeric value | |
| 786 | +==============+===============+ |
| 787 | | ``CRITICAL`` | 50 | |
| 788 | +--------------+---------------+ |
| 789 | | ``ERROR`` | 40 | |
| 790 | +--------------+---------------+ |
| 791 | | ``WARNING`` | 30 | |
| 792 | +--------------+---------------+ |
| 793 | | ``INFO`` | 20 | |
| 794 | +--------------+---------------+ |
| 795 | | ``DEBUG`` | 10 | |
| 796 | +--------------+---------------+ |
| 797 | | ``NOTSET`` | 0 | |
| 798 | +--------------+---------------+ |
| 799 | |
| 800 | Levels can also be associated with loggers, being set either by the developer or |
| 801 | through loading a saved logging configuration. When a logging method is called |
| 802 | on a logger, the logger compares its own level with the level associated with |
| 803 | the method call. If the logger's level is higher than the method call's, no |
| 804 | logging message is actually generated. This is the basic mechanism controlling |
| 805 | the verbosity of logging output. |
| 806 | |
| 807 | Logging messages are encoded as instances of the :class:`LogRecord` class. When |
| 808 | a logger decides to actually log an event, a :class:`LogRecord` instance is |
| 809 | created from the logging message. |
| 810 | |
| 811 | Logging messages are subjected to a dispatch mechanism through the use of |
| 812 | :dfn:`handlers`, which are instances of subclasses of the :class:`Handler` |
| 813 | class. Handlers are responsible for ensuring that a logged message (in the form |
| 814 | of a :class:`LogRecord`) ends up in a particular location (or set of locations) |
| 815 | which is useful for the target audience for that message (such as end users, |
| 816 | support desk staff, system administrators, developers). Handlers are passed |
| 817 | :class:`LogRecord` instances intended for particular destinations. Each logger |
| 818 | can have zero, one or more handlers associated with it (via the |
| 819 | :meth:`addHandler` method of :class:`Logger`). In addition to any handlers |
| 820 | directly associated with a logger, *all handlers associated with all ancestors |
| 821 | of the logger* are called to dispatch the message (unless the *propagate* flag |
| 822 | for a logger is set to a false value, at which point the passing to ancestor |
| 823 | handlers stops). |
| 824 | |
| 825 | Just as for loggers, handlers can have levels associated with them. A handler's |
| 826 | level acts as a filter in the same way as a logger's level does. If a handler |
| 827 | decides to actually dispatch an event, the :meth:`emit` method is used to send |
| 828 | the message to its destination. Most user-defined subclasses of :class:`Handler` |
| 829 | will need to override this :meth:`emit`. |
| 830 | |
| 831 | .. _custom-levels: |
| 832 | |
| 833 | Custom Levels |
| 834 | ^^^^^^^^^^^^^ |
| 835 | |
| 836 | Defining your own levels is possible, but should not be necessary, as the |
| 837 | existing levels have been chosen on the basis of practical experience. |
| 838 | However, if you are convinced that you need custom levels, great care should |
| 839 | be exercised when doing this, and it is possibly *a very bad idea to define |
| 840 | custom levels if you are developing a library*. That's because if multiple |
| 841 | library authors all define their own custom levels, there is a chance that |
| 842 | the logging output from such multiple libraries used together will be |
| 843 | difficult for the using developer to control and/or interpret, because a |
| 844 | given numeric value might mean different things for different libraries. |
| 845 | |
| 846 | .. _useful-handlers: |
| 847 | |
| 848 | Useful Handlers |
| 849 | --------------- |
| 850 | |
| 851 | In addition to the base :class:`Handler` class, many useful subclasses are |
| 852 | provided: |
| 853 | |
| 854 | #. :class:`StreamHandler` instances send messages to streams (file-like |
| 855 | objects). |
| 856 | |
| 857 | #. :class:`FileHandler` instances send messages to disk files. |
| 858 | |
| 859 | .. currentmodule:: logging.handlers |
| 860 | |
| 861 | #. :class:`BaseRotatingHandler` is the base class for handlers that |
| 862 | rotate log files at a certain point. It is not meant to be instantiated |
| 863 | directly. Instead, use :class:`RotatingFileHandler` or |
| 864 | :class:`TimedRotatingFileHandler`. |
| 865 | |
| 866 | #. :class:`RotatingFileHandler` instances send messages to disk |
| 867 | files, with support for maximum log file sizes and log file rotation. |
| 868 | |
| 869 | #. :class:`TimedRotatingFileHandler` instances send messages to |
| 870 | disk files, rotating the log file at certain timed intervals. |
| 871 | |
| 872 | #. :class:`SocketHandler` instances send messages to TCP/IP |
| 873 | sockets. |
| 874 | |
| 875 | #. :class:`DatagramHandler` instances send messages to UDP |
| 876 | sockets. |
| 877 | |
| 878 | #. :class:`SMTPHandler` instances send messages to a designated |
| 879 | email address. |
| 880 | |
| 881 | #. :class:`SysLogHandler` instances send messages to a Unix |
| 882 | syslog daemon, possibly on a remote machine. |
| 883 | |
| 884 | #. :class:`NTEventLogHandler` instances send messages to a |
| 885 | Windows NT/2000/XP event log. |
| 886 | |
| 887 | #. :class:`MemoryHandler` instances send messages to a buffer |
| 888 | in memory, which is flushed whenever specific criteria are met. |
| 889 | |
| 890 | #. :class:`HTTPHandler` instances send messages to an HTTP |
| 891 | server using either ``GET`` or ``POST`` semantics. |
| 892 | |
| 893 | #. :class:`WatchedFileHandler` instances watch the file they are |
| 894 | logging to. If the file changes, it is closed and reopened using the file |
| 895 | name. This handler is only useful on Unix-like systems; Windows does not |
| 896 | support the underlying mechanism used. |
| 897 | |
| 898 | #. :class:`QueueHandler` instances send messages to a queue, such as |
| 899 | those implemented in the :mod:`queue` or :mod:`multiprocessing` modules. |
| 900 | |
| 901 | .. currentmodule:: logging |
| 902 | |
| 903 | #. :class:`NullHandler` instances do nothing with error messages. They are used |
| 904 | by library developers who want to use logging, but want to avoid the 'No |
| 905 | handlers could be found for logger XXX' message which can be displayed if |
| 906 | the library user has not configured logging. See :ref:`library-config` for |
| 907 | more information. |
| 908 | |
| 909 | .. versionadded:: 3.1 |
| 910 | The :class:`NullHandler` class. |
| 911 | |
| 912 | .. versionadded:: 3.2 |
| 913 | The :class:`~logging.handlers.QueueHandler` class. |
| 914 | |
| 915 | The :class:`NullHandler`, :class:`StreamHandler` and :class:`FileHandler` |
| 916 | classes are defined in the core logging package. The other handlers are |
| 917 | defined in a sub- module, :mod:`logging.handlers`. (There is also another |
| 918 | sub-module, :mod:`logging.config`, for configuration functionality.) |
| 919 | |
| 920 | Logged messages are formatted for presentation through instances of the |
| 921 | :class:`Formatter` class. They are initialized with a format string suitable for |
| 922 | use with the % operator and a dictionary. |
| 923 | |
| 924 | For formatting multiple messages in a batch, instances of |
| 925 | :class:`BufferingFormatter` can be used. In addition to the format string (which |
| 926 | is applied to each message in the batch), there is provision for header and |
| 927 | trailer format strings. |
| 928 | |
| 929 | When filtering based on logger level and/or handler level is not enough, |
| 930 | instances of :class:`Filter` can be added to both :class:`Logger` and |
| 931 | :class:`Handler` instances (through their :meth:`addFilter` method). Before |
| 932 | deciding to process a message further, both loggers and handlers consult all |
| 933 | their filters for permission. If any filter returns a false value, the message |
| 934 | is not processed further. |
| 935 | |
| 936 | The basic :class:`Filter` functionality allows filtering by specific logger |
| 937 | name. If this feature is used, messages sent to the named logger and its |
| 938 | children are allowed through the filter, and all others dropped. |
| 939 | |
| 940 | |
| 941 | .. _logging-exceptions: |
| 942 | |
| 943 | Exceptions raised during logging |
| 944 | -------------------------------- |
| 945 | |
| 946 | The logging package is designed to swallow exceptions which occur while logging |
| 947 | in production. This is so that errors which occur while handling logging events |
| 948 | - such as logging misconfiguration, network or other similar errors - do not |
| 949 | cause the application using logging to terminate prematurely. |
| 950 | |
| 951 | :class:`SystemExit` and :class:`KeyboardInterrupt` exceptions are never |
| 952 | swallowed. Other exceptions which occur during the :meth:`emit` method of a |
| 953 | :class:`Handler` subclass are passed to its :meth:`handleError` method. |
| 954 | |
| 955 | The default implementation of :meth:`handleError` in :class:`Handler` checks |
| 956 | to see if a module-level variable, :data:`raiseExceptions`, is set. If set, a |
| 957 | traceback is printed to :data:`sys.stderr`. If not set, the exception is swallowed. |
| 958 | |
| 959 | **Note:** The default value of :data:`raiseExceptions` is ``True``. This is because |
| 960 | during development, you typically want to be notified of any exceptions that |
| 961 | occur. It's advised that you set :data:`raiseExceptions` to ``False`` for production |
| 962 | usage. |
| 963 | |
| 964 | .. currentmodule:: logging |
| 965 | |
| 966 | .. _arbitrary-object-messages: |
| 967 | |
| 968 | Using arbitrary objects as messages |
| 969 | ----------------------------------- |
| 970 | |
| 971 | In the preceding sections and examples, it has been assumed that the message |
| 972 | passed when logging the event is a string. However, this is not the only |
| 973 | possibility. You can pass an arbitrary object as a message, and its |
| 974 | :meth:`__str__` method will be called when the logging system needs to convert |
| 975 | it to a string representation. In fact, if you want to, you can avoid |
| 976 | computing a string representation altogether - for example, the |
| 977 | :class:`SocketHandler` emits an event by pickling it and sending it over the |
| 978 | wire. |
| 979 | |
| 980 | |
| 981 | Optimization |
| 982 | ------------ |
| 983 | |
| 984 | Formatting of message arguments is deferred until it cannot be avoided. |
| 985 | However, computing the arguments passed to the logging method can also be |
| 986 | expensive, and you may want to avoid doing it if the logger will just throw |
| 987 | away your event. To decide what to do, you can call the :meth:`isEnabledFor` |
| 988 | method which takes a level argument and returns true if the event would be |
| 989 | created by the Logger for that level of call. You can write code like this:: |
| 990 | |
| 991 | if logger.isEnabledFor(logging.DEBUG): |
| 992 | logger.debug('Message with %s, %s', expensive_func1(), |
| 993 | expensive_func2()) |
| 994 | |
| 995 | so that if the logger's threshold is set above ``DEBUG``, the calls to |
| 996 | :func:`expensive_func1` and :func:`expensive_func2` are never made. |
| 997 | |
| 998 | There are other optimizations which can be made for specific applications which |
| 999 | need more precise control over what logging information is collected. Here's a |
| 1000 | list of things you can do to avoid processing during logging which you don't |
| 1001 | need: |
| 1002 | |
| 1003 | +-----------------------------------------------+----------------------------------------+ |
| 1004 | | What you don't want to collect | How to avoid collecting it | |
| 1005 | +===============================================+========================================+ |
| 1006 | | Information about where calls were made from. | Set ``logging._srcfile`` to ``None``. | |
| 1007 | +-----------------------------------------------+----------------------------------------+ |
| 1008 | | Threading information. | Set ``logging.logThreads`` to ``0``. | |
| 1009 | +-----------------------------------------------+----------------------------------------+ |
| 1010 | | Process information. | Set ``logging.logProcesses`` to ``0``. | |
| 1011 | +-----------------------------------------------+----------------------------------------+ |
| 1012 | |
| 1013 | Also note that the core logging module only includes the basic handlers. If |
| 1014 | you don't import :mod:`logging.handlers` and :mod:`logging.config`, they won't |
| 1015 | take up any memory. |
| 1016 | |