txaio icon indicating copy to clipboard operation
txaio copied to clipboard

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

Open blinkingmatt opened this issue 6 years ago • 1 comments

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() )

blinkingmatt avatar May 03 '18 07:05 blinkingmatt

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.

sethrh avatar Apr 02 '20 18:04 sethrh