logger_tt
logger_tt copied to clipboard
Fix non-`%`-style formatting
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.
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.
In other words, this knocks down the first hurdle, not everything.
Ah. The QueueHandler is always using the default formatter. Let me see if I can fix that...
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.
======================================================================== 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) ==============================================================
Skipped tests were:
- The Telegram ones, as I do not have an account (nor do I wish one).
test_multiline, which is skipped on Python 3.7+ and this is Python 3.11test_deadlock, which is marked as an unconditional skip (which is good, becauseexception_deadlock.pydoesn't exist!)