I\'d like to have loglevel TRACE (5) for my application, as I don\'t think that debug()
is sufficient. Additionally log(5, msg)
isn\'t what I want.
While we have already plenty of correct answers, the following is in my opinion more pythonic:
import logging
from functools import partial, partialmethod
logging.TRACE = 5
logging.addLevelName(logging.TRACE, 'TRACE')
logging.Logger.trace = partialmethod(logging.Logger.log, logging.TRACE)
logging.trace = partial(logging.log, logging.TRACE)
If you want to use mypy
on your code, it is recommended to add # type: ignore
to suppress warnings from adding attribute.