logger_tt icon indicating copy to clipboard operation
logger_tt copied to clipboard

Fix non-`%`-style formatting

Open nonnull-ca opened this issue 2 years ago • 6 comments
trafficstars

I dug into #22 a little, and it appears as though the problem is here:

    def __init__(self, fmt: str = '', datefmt: str = '', style: str = ''):
        super(DefaultFormatter, self).__init__(fmt=fmt, datefmt=datefmt)

        self._logger_tt_formatters = {}
        for case, fmt in self._standardize(fmt).items():
            self._logger_tt_formatters[case] = logging.Formatter(fmt=fmt, datefmt=datefmt, style=style)

Note that the initial super() call does not pass along style, but then it passes the same fmt into the underlying logging.Formatters with style. Then then results in the same format string being interpreted as %-style and {-style in different places.

nonnull-ca avatar May 07 '23 03:05 nonnull-ca

Sure, shall do.

That being said, I'm hitting problems still. In particular, the 'automagicially'-instantiated root logger is instantiated in the import, which is necessarily before the call to basic_config. This then results in said root logger always using %-style formatting regardless of config... and because said root logger is, well, the root, this then results in all logging dying.

nonnull-ca avatar May 07 '23 04:05 nonnull-ca

In other words, this knocks down the first hurdle, not everything.

nonnull-ca avatar May 07 '23 04:05 nonnull-ca

Ah. The QueueHandler is always using the default formatter. Let me see if I can fix that...

nonnull-ca avatar May 07 '23 19:05 nonnull-ca

As it turns out, style does not do what I think it did :/

It purely affects the style of the format string passed to the formatter, not the format of the log message itself.

There are still some fixes required for this to work - that I'll push in a few minutes along with an associated test - but looks like I'll still need to do my 'usual' wrapper to make {} work.

nonnull-ca avatar May 07 '23 19:05 nonnull-ca

======================================================================== test session starts ========================================================================
platform linux -- Python 3.11.2, pytest-7.1.2, pluggy-1.0.0
rootdir: [...]/logger_tt
plugins: xdist-3.2.1, timeout-2.1.0, hypothesis-6.29.3
collected 69 items                                                                                                                                                  

test_brace_style.py .                                                                                                                                         [  1%]
test_edit_log_path.py ..                                                                                                                                      [  4%]
test_handlers.py ....sss....                                                                                                                                  [ 20%]
test_inspector.py ..........s.s.........                                                                                                                      [ 52%]
test_multiprocessing.py ..........                                                                                                                            [ 66%]
test_recur_exception.py ..                                                                                                                                    [ 69%]
test_simple.py ....................                                                                                                                           [ 98%]
test_theading.py .                                                                                                                                            [100%]

============================================================= 64 passed, 5 skipped in 90.38s (0:01:30) ==============================================================

nonnull-ca avatar May 07 '23 20:05 nonnull-ca

Skipped tests were:

  1. The Telegram ones, as I do not have an account (nor do I wish one).
  2. test_multiline, which is skipped on Python 3.7+ and this is Python 3.11
  3. test_deadlock, which is marked as an unconditional skip (which is good, because exception_deadlock.py doesn't exist!)

nonnull-ca avatar May 07 '23 20:05 nonnull-ca