Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(33)

Unified Diff: Doc/howto/logging-cookbook.rst

Issue 18759: Fix internal doc references for logging package (Closed)
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Doc/howto/logging.rst » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Doc/howto/logging-cookbook.rst Fri Aug 16 19:36:18 2013 +0200
+++ b/Doc/howto/logging-cookbook.rst Fri Aug 16 22:21:58 2013 +0300
@@ -97,7 +97,8 @@
Multiple handlers and formatters
--------------------------------
-Loggers are plain Python objects. The :func:`addHandler` method has no minimum
+Loggers are plain Python objects. The :meth:`~Logger.addHandler` method has no
+minimum
or maximum quota for the number of handlers you may add. Sometimes it will be
beneficial for an application to log all messages of all severities to a text
file while simultaneously logging errors or above to the console. To set this
@@ -459,7 +460,8 @@
Note that there are some security issues with pickle in some scenarios. If
these affect you, you can use an alternative serialization scheme by overriding
-the :meth:`makePickle` method and implementing your alternative there, as
+the :meth:`~SocketHandler.makePickle` method and implementing your alternative
+there, as
well as adapting the above script to use your alternative serialization.
@@ -468,6 +470,8 @@
Adding contextual information to your logging output
----------------------------------------------------
+.. currentmodule:: logging
+
Sometimes you want logging output to contain contextual information in
addition to the parameters passed to the logging call. For example, in a
networked application, it may be desirable to log client-specific information
@@ -509,7 +513,8 @@
msg, kwargs = self.process(msg, kwargs)
self.logger.debug(msg, *args, **kwargs)
-The :meth:`process` method of :class:`LoggerAdapter` is where the contextual
+The :meth:`~LoggerAdapter.process` method of :class:`LoggerAdapter` is where
+the contextual
information is added to the logging output. It's passed the message and
keyword arguments of the logging call, and it passes back (potentially)
modified versions of these to use in the call to the underlying logger. The
@@ -523,8 +528,8 @@
customized strings with your :class:`Formatter` instances which know about
the keys of the dict-like object. If you need a different method, e.g. if you
want to prepend or append the contextual information to the message string,
-you just need to subclass :class:`LoggerAdapter` and override :meth:`process`
-to do what you need. Here is a simple example::
+you just need to subclass :class:`LoggerAdapter` and override
+:meth:`~LoggerAdapter.process` to do what you need. Here is a simple example::
class CustomAdapter(logging.LoggerAdapter):
"""
@@ -633,7 +638,8 @@
*multiple processes* is *not* supported, because there is no standard way to
serialize access to a single file across multiple processes in Python. If you
need to log to a single file from multiple processes, one way of doing this is
-to have all the processes log to a :class:`SocketHandler`, and have a separate
+to have all the processes log to a :class:`~handlers.SocketHandler`, and have a
+separate
process which implements a socket server which reads from the socket and logs
to file. (If you prefer, you can dedicate one thread in one of the existing
processes to perform this function.) :ref:`This section <network-logging>`
@@ -643,16 +649,16 @@
If you are using a recent version of Python which includes the
:mod:`multiprocessing` module, you could write your own handler which uses the
-:class:`Lock` class from this module to serialize access to the file from
+:class:`~multiprocessing.Lock` class from this module to serialize access to
+the file from
your processes. The existing :class:`FileHandler` and subclasses do not make
use of :mod:`multiprocessing` at present, though they may do so in the future.
Note that at present, the :mod:`multiprocessing` module does not provide
working lock functionality on all platforms (see
http://bugs.python.org/issue3770).
-.. currentmodule:: logging.handlers
-
-Alternatively, you can use a ``Queue`` and a :class:`QueueHandler` to send
+Alternatively, you can use a ``Queue`` and a :class:`~handlers.QueueHandler`
+to send
all logging events to one of the processes in your multi-process application.
The following example script demonstrates how you can do this; in the example
a separate listener process listens for events sent by other processes and logs
@@ -878,7 +884,7 @@
file and log to that. You may want to keep a certain number of these files, and
when that many files have been created, rotate the files so that the number of
files and the size of the files both remain bounded. For this usage pattern, the
-logging package provides a :class:`RotatingFileHandler`::
+logging package provides a :class:`~handlers.RotatingFileHandler`::
import glob
import logging
@@ -1176,7 +1182,8 @@
Subclassing QueueHandler - a ZeroMQ example
-------------------------------------------
-You can use a :class:`QueueHandler` subclass to send messages to other kinds
+You can use a :class:`~handlers.QueueHandler` subclass to send messages to
+other kinds
of queues, for example a ZeroMQ 'publish' socket. In the example below,the
socket is created separately and passed to the handler (as its 'queue')::
@@ -1216,7 +1223,8 @@
Subclassing QueueListener - a ZeroMQ example
--------------------------------------------
-You can also subclass :class:`QueueListener` to get messages from other kinds
+You can also subclass :class:`~handlers.QueueListener` to get messages from
+other kinds
of queues, for example a ZeroMQ 'subscribe' socket. Here's an example::
class ZeroMQSocketListener(QueueListener):
« no previous file with comments | « no previous file | Doc/howto/logging.rst » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+