Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4039aff8
Commit
4039aff8
authored
Sep 11, 2010
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #9827: clarified LogRecord documentation.
parent
bd88802c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
19 deletions
+60
-19
Doc/library/logging.rst
Doc/library/logging.rst
+60
-19
No files found.
Doc/library/logging.rst
View file @
4039aff8
...
...
@@ -527,6 +527,7 @@ libraries, then the logger name specified can be "orgname.foo" rather than
just
"foo"
.
..
versionadded
::
3.1
The
:
class
:`
NullHandler
`
class
was
not
present
in
previous
versions
,
but
is
now
included
,
so
that
it
need
not
be
defined
in
library
code
.
...
...
@@ -736,7 +737,7 @@ functions.
d
=
{
'clientip'
:
'192.168.0.1'
,
'user'
:
'fbloggs'
}
logging
.
warning
(
"Protocol problem: %s"
,
"connection reset"
,
extra
=
d
)
would
print
something
like
::
would
print
something
like
::
2006
-
02
-
08
22
:
20
:
02
,
165
192.168.0.1
fbloggs
Protocol
problem
:
connection
reset
...
...
@@ -903,6 +904,7 @@ functions.
and
2.2
.
x
,
which
do
not
include
the
:
mod
:`
logging
`
package
in
the
standard
library
.
..
_logger
:
Logger
Objects
--------------
...
...
@@ -1788,6 +1790,8 @@ these affect you, you can use an alternative serialization scheme by overriding
the :meth:`makePickle` method and implementing your alternative there, as
well as adapting the above script to use your alternative serialization.
.. _arbitrary-object-messages:
Using arbitrary objects as messages
-----------------------------------
...
...
@@ -2705,7 +2709,6 @@ Currently, the useful mapping keys in a :class:`LogRecord` are:
specified
,
``
'%(message)s'
``
is
used
.
If
no
*
datefmt
*
is
specified
,
the
ISO8601
date
format
is
used
.
..
method
::
format
(
record
)
The
record
's attribute dictionary is used as the operand to a string
...
...
@@ -2781,32 +2784,70 @@ been applied to those descendant loggers.
LogRecord Objects
-----------------
:class:`LogRecord` instances are created every time something is logged. They
contain all the information pertinent to the event being logged. The main
information passed in is in msg and args, which are combined using msg % args to
create the message field of the record. The record also includes information
such as when the record was created, the source line where the logging call was
made, and any exception information to be logged.
:class:`LogRecord` instances are created automatically by the :class:`Logger`
every time something is logged, and can be created manually via
:func:`makeLogRecord` (for example, from a pickled event received over the
wire).
.. class:: LogRecord(name, lvl, pathname, lineno, msg, args, exc_info, func=None)
Returns an instance of :class:`LogRecord` initialized with interesting
information. The *name* is the logger name; *lvl* is the numeric level;
*pathname* is the absolute pathname of the source file in which the logging
call was made; *lineno* is the line number in that file where the logging
call is found; *msg* is the user-supplied message (a format string); *args*
is the tuple which, together with *msg*, makes up the user message; and
*exc_info* is the exception tuple obtained by calling :func:`sys.exc_info`
(or :const:`None`, if no exception information is available). The *func* is
the name of the function from which the logging call was made. If not
specified, it defaults to ``None``.
Contains all the information pertinent to the event being logged.
The primary information is passed in :attr:`msg` and :attr:`args`, which
are combined using ``msg % args`` to create the :attr:`message` field of the
record.
.. attribute:: args
Tuple of arguments to be used in formatting :attr:`msg`.
.. attribute:: exc_info
Exception tuple (à la `sys.exc_info`) or `None` if no exception
information is availble.
.. attribute:: func
Name of the function of origin (i.e. in which the logging call was made).
.. attribute:: lineno
Line number in the source file of origin.
.. attribute:: lvl
Numeric logging level.
.. attribute:: message
Bound to the result of :meth:`getMessage` when
:meth:`Formatter.format(record)<Formatter.format>` is invoked.
.. attribute:: msg
User-supplied :ref:`format string<string-formatting>` or arbitrary object
(see :ref:`arbitrary-object-messages`) used in :meth:`getMessage`.
.. attribute:: name
Name of the logger that emitted the record.
.. attribute:: pathname
Absolute pathname of the source file of origin.
.. method:: getMessage()
Returns the message for this :class:`LogRecord` instance after merging any
user-supplied arguments with the message.
user-supplied arguments with the message. If the user-supplied message
argument to the logging call is not a string, :func:`str` is called on it to
convert it to a string. This allows use of user-defined classes as
messages, whose ``__str__`` method can return the actual format string to
be used.
.. versionchanged:: 2.5
*func* was added.
.. _logger-adapter:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment