This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: LoggerAdapter class lacks documented "setLevel" method
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Eric.Hanchrow, python-dev, vinay.sajip
Priority: normal Keywords:

Created on 2013-10-30 22:52 by Eric.Hanchrow, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg201783 - (view) Author: Eric Hanchrow (Eric.Hanchrow) * Date: 2013-10-30 23:01
Put the following into a file named "repro.py", then type "python repro.py" at your shell.  You'll see ``AttributeError: 'CustomAdapter' object has no attribute 'setLevel'``

import logging logging.basicConfig ()

class CustomAdapter(logging.LoggerAdapter):
    def process(self, msg, kwargs):
        return '[%s] %s' % (self.extra['connid'], msg), kwargs

logger = logging.getLogger(__name__) 
adapter = CustomAdapter(logger, {'connid': '1234'}) 
adapter.setLevel (logging.WARN) 
adapter.warning ("Ahoy matey")
msg201785 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2013-10-30 23:28
The adapter provides only the logging methods such as debug(), info() etc., but not methods to configure the logger (such as setLevel). Just use

adapter.logger.setLevel(logging.WARNING)
msg201787 - (view) Author: Eric Hanchrow (Eric.Hanchrow) * Date: 2013-10-30 23:41
I should have been clearer: the problem is that the docs (http://docs.python.org/2/library/logging.html#logging.LoggerAdapter) say 

In addition to the above, LoggerAdapter supports the following methods of Logger, i.e. debug(), info(), warning(), error(), exception(), critical(), log(), isEnabledFor(), getEffectiveLevel(), setLevel(), hasHandlers(). 

So the code and the docs disagree.
msg201788 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2013-10-31 00:36
Okay, I see. I can't add the methods to the code (as feature additions aren't allowed in micro releases, and 2.7 is the last 2.x release). So I'll update the documentation.
msg201789 - (view) Author: Eric Hanchrow (Eric.Hanchrow) * Date: 2013-10-31 01:08
Thanks!

On Wed, Oct 30, 2013 at 5:36 PM, Vinay Sajip <report@bugs.python.org> wrote:
>
> Vinay Sajip added the comment:
>
> Okay, I see. I can't add the methods to the code (as feature additions aren't allowed in micro releases, and 2.7 is the last 2.x release). So I'll update the documentation.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue19455>
> _______________________________________
msg201790 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-10-31 01:11
New changeset db40b69f9c0a by Vinay Sajip in branch '2.7':
Issue #19455: Corrected inaccuracies in documentation and corrected some incorrect cross-references.
http://hg.python.org/cpython/rev/db40b69f9c0a
History
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63654
2013-10-31 01:11:53python-devsetnosy: + python-dev
messages: + msg201790
2013-10-31 01:08:16Eric.Hanchrowsetmessages: + msg201789
2013-10-31 00:36:10vinay.sajipsetmessages: + msg201788
2013-10-30 23:41:14Eric.Hanchrowsetmessages: + msg201787
2013-10-30 23:28:04vinay.sajipsetstatus: open -> closed

nosy: + vinay.sajip
messages: + msg201785

resolution: not a bug
2013-10-30 23:01:38Eric.Hanchrowsetmessages: + msg201783
2013-10-30 22:52:55Eric.Hanchrowcreate