CleverToolsFormatter is the custom formatter used by the built-in logging handlers in clevertools.
CleverToolsFormatter(
fmt: str,
datefmt: str | None = None,
*,
use_colors: bool = False,
)- injects
%(date)sand%(time)sinto each log record - can colorize
%(levelname)swhen output is written to a TTY - restores original record values after formatting so other handlers are not polluted
import logging
from clevertools import CleverToolsFormatter
handler = logging.StreamHandler()
handler.setFormatter(
CleverToolsFormatter(
"%(name)s | %(levelname)s | [%(date)s] [%(time)s] = %(message)s",
use_colors=False,
)
)import logging
from clevertools import CleverToolsFormatter
handler = logging.StreamHandler()
handler.setFormatter(
CleverToolsFormatter(
"[%(date)s %(time)s] %(levelname)s %(message)s",
use_colors=False,
)
)datefmtonly matters when your format string uses fields such as%(asctime)s.- The formatter's custom
%(date)sand%(time)sfields always use the library's internal date and time formats.