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
c84f0169
Commit
c84f0169
authored
Sep 21, 2010
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some methods to LoggerAdapter, and updated documentation.
parent
ceff5668
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
9 deletions
+32
-9
Doc/library/logging.rst
Doc/library/logging.rst
+11
-8
Lib/logging/__init__.py
Lib/logging/__init__.py
+14
-0
Lib/logging/handlers.py
Lib/logging/handlers.py
+2
-0
Lib/test/test_logging.py
Lib/test/test_logging.py
+1
-1
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Doc/library/logging.rst
View file @
c84f0169
...
@@ -2599,8 +2599,8 @@ should, then :meth:`flush` is expected to do the needful.
...
@@ -2599,8 +2599,8 @@ should, then :meth:`flush` is expected to do the needful.
.. method:: flush()
.. method:: flush()
For a :class:`MemoryHandler`, flushing means just sending the buffered
For a :class:`MemoryHandler`, flushing means just sending the buffered
records to the target, if there is one.
Override if you want different
records to the target, if there is one.
The buffer is also cleared when
behavior.
this happens. Override if you want different
behavior.
.. method:: setTarget(target)
.. method:: setTarget(target)
...
@@ -2972,15 +2972,18 @@ __ context-info_
...
@@ -2972,15 +2972,18 @@ __ context-info_
'
extra
'. The return value is a (*msg*, *kwargs*) tuple which has the
'
extra
'. The return value is a (*msg*, *kwargs*) tuple which has the
(possibly modified) versions of the arguments passed in.
(possibly modified) versions of the arguments passed in.
In addition to the above, :class:`LoggerAdapter` supports
all the logg
ing
In addition to the above, :class:`LoggerAdapter` supports
the follow
ing
methods of :class:`Logger`, i.e. :meth:`debug`, :meth:`info`, :meth:`warning`,
methods of :class:`Logger`, i.e. :meth:`debug`, :meth:`info`, :meth:`warning`,
:meth:`error`, :meth:`exception`, :meth:`critical` and :meth:`log`. These
:meth:`error`, :meth:`exception`, :meth:`critical`, :meth:`log`,
methods have the same signatures as their counterparts in :class:`Logger`, so
:meth:`isEnabledFor`, :meth:`getEffectiveLevel`, :meth:`setLevel`,
you can use the two types of instances interchangeably.
:meth:`hasHandlers`. These methods have the same signatures as their
counterparts in :class:`Logger`, so you can use the two types of instances
interchangeably.
.. versionchanged:: 3.2
.. versionchanged:: 3.2
The :meth:`isEnabledFor` method was added to :class:`LoggerAdapter`. This
The :meth:`isEnabledFor`, :meth:`getEffectiveLevel`, :meth:`setLevel` and
method delegates to the underlying logger.
:meth:`hasHandlers` methods were added to :class:`LoggerAdapter`. These
methods delegate to the underlying logger.
Thread Safety
Thread Safety
...
...
Lib/logging/__init__.py
View file @
c84f0169
...
@@ -1400,6 +1400,8 @@ class LoggerAdapter(object):
...
@@ -1400,6 +1400,8 @@ class LoggerAdapter(object):
msg
,
kwargs
=
self
.
process
(
msg
,
kwargs
)
msg
,
kwargs
=
self
.
process
(
msg
,
kwargs
)
self
.
logger
.
warning
(
msg
,
*
args
,
**
kwargs
)
self
.
logger
.
warning
(
msg
,
*
args
,
**
kwargs
)
warn
=
warning
def
error
(
self
,
msg
,
*
args
,
**
kwargs
):
def
error
(
self
,
msg
,
*
args
,
**
kwargs
):
"""
"""
Delegate an error call to the underlying logger, after adding
Delegate an error call to the underlying logger, after adding
...
@@ -1433,12 +1435,24 @@ class LoggerAdapter(object):
...
@@ -1433,12 +1435,24 @@ class LoggerAdapter(object):
msg
,
kwargs
=
self
.
process
(
msg
,
kwargs
)
msg
,
kwargs
=
self
.
process
(
msg
,
kwargs
)
self
.
logger
.
log
(
level
,
msg
,
*
args
,
**
kwargs
)
self
.
logger
.
log
(
level
,
msg
,
*
args
,
**
kwargs
)
def
setLevel
(
self
,
level
):
"""
Set the specified level on the underlying logger.
"""
self
.
logger
.
setLevel
(
level
)
def
isEnabledFor
(
self
,
level
):
def
isEnabledFor
(
self
,
level
):
"""
"""
See if the underlying logger is enabled for the specified level.
See if the underlying logger is enabled for the specified level.
"""
"""
return
self
.
logger
.
isEnabledFor
(
level
)
return
self
.
logger
.
isEnabledFor
(
level
)
def
getEffectiveLevel
(
self
):
"""
Get the effective level for the underlying logger.
"""
return
self
.
logger
.
getEffectiveLevel
()
def
hasHandlers
(
self
):
def
hasHandlers
(
self
):
"""
"""
See if the underlying logger has any handlers.
See if the underlying logger has any handlers.
...
...
Lib/logging/handlers.py
View file @
c84f0169
...
@@ -1131,6 +1131,8 @@ class MemoryHandler(BufferingHandler):
...
@@ -1131,6 +1131,8 @@ class MemoryHandler(BufferingHandler):
For a MemoryHandler, flushing means just sending the buffered
For a MemoryHandler, flushing means just sending the buffered
records to the target, if there is one. Override if you want
records to the target, if there is one. Override if you want
different behaviour.
different behaviour.
The record buffer is also cleared by this operation.
"""
"""
if
self
.
target
:
if
self
.
target
:
for
record
in
self
.
buffer
:
for
record
in
self
.
buffer
:
...
...
Lib/test/test_logging.py
View file @
c84f0169
...
@@ -154,7 +154,7 @@ class BuiltinLevelsTest(BaseTest):
...
@@ -154,7 +154,7 @@ class BuiltinLevelsTest(BaseTest):
ERR = logging.getLogger("
ERR
")
ERR = logging.getLogger("
ERR
")
ERR.setLevel(logging.ERROR)
ERR.setLevel(logging.ERROR)
INF = logging.
getLogger("
INF
"
)
INF = logging.
LoggerAdapter(logging.getLogger("
INF
"), {}
)
INF.setLevel(logging.INFO)
INF.setLevel(logging.INFO)
DEB = logging.getLogger("
DEB
")
DEB = logging.getLogger("
DEB
")
DEB.setLevel(logging.DEBUG)
DEB.setLevel(logging.DEBUG)
...
...
Misc/NEWS
View file @
c84f0169
...
@@ -58,6 +58,10 @@ Core and Builtins
...
@@ -58,6 +58,10 @@ Core and Builtins
Library
Library
-------
-------
- logging: hasHandlers method was added to Logger, and isEnabledFor,
getEffectiveLevel, hasHandlers and setLevel were added to LoggerAdapter.
LoggerAdapter was introduced into the unit tests for logging.
- Issue #1686: Fix string.Template when overriding the pattern attribute.
- Issue #1686: Fix string.Template when overriding the pattern attribute.
- Issue #9854: SocketIO objects now observe the RawIOBase interface in
- Issue #9854: SocketIO objects now observe the RawIOBase interface in
...
...
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