Created
September 9, 2022 14:33
-
-
Save geryxyz/9d9f2f4da596d94abd3f257d962b2c64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from typing import Callable | |
class LambdaFormatter(logging.Formatter): | |
def __init__( | |
self, | |
fmt, | |
pre_format_func: Callable[[logging.LogRecord], logging.LogRecord] = lambda text: text, | |
post_format_func: Callable[[str, logging.LogRecord], str] = lambda text, _: text | |
): | |
super().__init__(fmt) | |
self.pre_format_func = pre_format_func | |
self.post_format_func = post_format_func | |
def format(self, record: logging.LogRecord) -> str: | |
log_fmt = self.post_format_func(super().format(self.pre_format_func(record)), record) | |
return log_fmt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment