Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aio._TxaioLogWrapper._set_log_level does not set log level in underlying logging.Logger instance #131

Open
blinkingmatt opened this issue May 3, 2018 · 1 comment

Comments

@blinkingmatt
Copy link

System:

  • Windows 10
  • Python 3.6
  • txaio 2.10.0

The txaio logging framework delegates the info, warning and the like calls to a "logging.Logger" instance.
But calling "_TxaioLogWrapper._set_log_level" does not set log level in underlying "logging.Logger" instance.
The corresponding methods of "logging.Logger" check for the effective log level. Without setting the log level in "_set_log_level" the log level of the root logger (parent) is always used.

I suggest a small addition in _"_TxaioLogWrapper.set_log_level":

class _TxaioLogWrapper(ILogger):
    ......

    def _set_log_level(self, level):
        target_level = log_levels.index(level)
        # this binds either _log or _no_op above to this instance,
        # depending on the desired level.
        for (idx, name) in enumerate(log_levels):
            if idx <= target_level:
                log_method = functools.partial(_log, self, name)
            else:
                log_method = _no_op
            setattr(self, name, log_method)
        self._log_level = level
        
        # must set log level in logger
        if level == 'trace':
            level = 'debug'
        self._logger.setLevel( level.upper() )
@sethrh
Copy link

sethrh commented Apr 2, 2020

I just spent the last couple hours tracking this down, and of course didn't find this bug until I was done. Still same issue in txaio 20.4.1. I made a gist to repro: https://gist.github.com/sethrh/331cadc538051cb0c0eb1de001a3b70f

I found this because I wanted to set my logger's level to debug, while setting all of the autobahn.websocket* loggers to warn.

Additionally, individual loggers should have an interface to set their log levels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants