~pythonregexp2.7/python/issue2636-09-01+10

« back to all changes in this revision

Viewing changes to Doc/library/logging.rst

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-05-24 18:56:40 UTC
  • mfrom: (39055.1.22 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080524185640-59vz6l1f7qgixgal
Merged in changes from the Single-Loop Engine branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
698
698
   :func:`error` and :func:`critical` will call :func:`basicConfig` automatically
699
699
   if no handlers are defined for the root logger.
700
700
 
 
701
   This function does nothing if the root logger already has handlers configured.
 
702
 
701
703
   .. versionchanged:: 2.4
702
704
      Formerly, :func:`basicConfig` did not take any keyword arguments.
703
705
 
1297
1299
   logger2.warning('Jail zesty vixen who grabbed pay from quack.')
1298
1300
   logger2.error('The five boxing wizards jump quickly.')
1299
1301
 
1300
 
At the receiving end, you can set up a receiver using the :mod:`SocketServer`
 
1302
At the receiving end, you can set up a receiver using the :mod:`socketserver`
1301
1303
module. Here is a basic working example::
1302
1304
 
1303
1305
   import cPickle
1304
1306
   import logging
1305
1307
   import logging.handlers
1306
 
   import SocketServer
 
1308
   import socketserver
1307
1309
   import struct
1308
1310
 
1309
1311
 
1310
 
   class LogRecordStreamHandler(SocketServer.StreamRequestHandler):
 
1312
   class LogRecordStreamHandler(socketserver.StreamRequestHandler):
1311
1313
       """Handler for a streaming logging request.
1312
1314
 
1313
1315
       This basically logs the record using whatever logging policy is
1349
1351
           # cycles and network bandwidth!
1350
1352
           logger.handle(record)
1351
1353
 
1352
 
   class LogRecordSocketReceiver(SocketServer.ThreadingTCPServer):
 
1354
   class LogRecordSocketReceiver(socketserver.ThreadingTCPServer):
1353
1355
       """simple TCP socket-based logging receiver suitable for testing.
1354
1356
       """
1355
1357
 
1358
1360
       def __init__(self, host='localhost',
1359
1361
                    port=logging.handlers.DEFAULT_TCP_LOGGING_PORT,
1360
1362
                    handler=LogRecordStreamHandler):
1361
 
           SocketServer.ThreadingTCPServer.__init__(self, (host, port), handler)
 
1363
           socketserver.ThreadingTCPServer.__init__(self, (host, port), handler)
1362
1364
           self.abort = 0
1363
1365
           self.timeout = 1
1364
1366
           self.logname = None
2238
2240
 
2239
2241
.. function:: fileConfig(fname[, defaults])
2240
2242
 
2241
 
   Reads the logging configuration from a ConfigParser-format file named *fname*.
2242
 
   This function can be called several times from an application, allowing an end
2243
 
   user the ability to select from various pre-canned configurations (if the
2244
 
   developer provides a mechanism to present the choices and load the chosen
2245
 
   configuration). Defaults to be passed to ConfigParser can be specified in the
2246
 
   *defaults* argument.
 
2243
   Reads the logging configuration from a :mod:`configparser`\-format file named
 
2244
   *fname*.  This function can be called several times from an application,
 
2245
   allowing an end user the ability to select from various pre-canned
 
2246
   configurations (if the developer provides a mechanism to present the choices
 
2247
   and load the chosen configuration). Defaults to be passed to the ConfigParser
 
2248
   can be specified in the *defaults* argument.
2247
2249
 
2248
2250
 
2249
2251
.. function:: listen([port])
2273
2275
Configuration file format
2274
2276
^^^^^^^^^^^^^^^^^^^^^^^^^
2275
2277
 
2276
 
The configuration file format understood by :func:`fileConfig` is based on
2277
 
ConfigParser functionality. The file must contain sections called ``[loggers]``,
2278
 
``[handlers]`` and ``[formatters]`` which identify by name the entities of each
2279
 
type which are defined in the file. For each such entity, there is a separate
2280
 
section which identified how that entity is configured. Thus, for a logger named
2281
 
``log01`` in the ``[loggers]`` section, the relevant configuration details are
2282
 
held in a section ``[logger_log01]``. Similarly, a handler called ``hand01`` in
2283
 
the ``[handlers]`` section will have its configuration held in a section called
2284
 
``[handler_hand01]``, while a formatter called ``form01`` in the
2285
 
``[formatters]`` section will have its configuration specified in a section
2286
 
called ``[formatter_form01]``. The root logger configuration must be specified
2287
 
in a section called ``[logger_root]``.
 
2278
The configuration file format understood by :func:`fileConfig` is
 
2279
based on :mod:`configparser` functionality. The file must contain
 
2280
sections called ``[loggers]``, ``[handlers]`` and ``[formatters]``
 
2281
which identify by name the entities of each type which are defined in
 
2282
the file. For each such entity, there is a separate section which
 
2283
identified how that entity is configured. Thus, for a logger named
 
2284
``log01`` in the ``[loggers]`` section, the relevant configuration
 
2285
details are held in a section ``[logger_log01]``. Similarly, a handler
 
2286
called ``hand01`` in the ``[handlers]`` section will have its
 
2287
configuration held in a section called ``[handler_hand01]``, while a
 
2288
formatter called ``form01`` in the ``[formatters]`` section will have
 
2289
its configuration specified in a section called
 
2290
``[formatter_form01]``. The root logger configuration must be
 
2291
specified in a section called ``[logger_root]``.
2288
2292
 
2289
2293
Examples of these sections in the file are given below. ::
2290
2294