Skip to content

eds_scikit.utils.logging

formatter

formatter(record: dict)

Formats the logging message by:

  • Adding color and bold
  • Indenting the message
Source code in eds_scikit/utils/logging.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def formatter(record: dict):
    """
    Formats the logging message by:

    - Adding color and bold
    - Indenting the message
    """

    base_format = (
        "<b>"  # bold
        "<light-blue>[eds-scikit]</light-blue>"
        "- "
        "{name}:"  # corresponds to __name__
        "{extra[classname]}{extra[sep]}"  # class name, if relevant
        "</b>"
        "{function}"  # function name
    )
    colored_format = Colorizer.ansify(base_format)
    colored_message = Colorizer.ansify(str(record["message"]))

    escaped_record = escape(record)
    base = colored_format.format(**escaped_record)

    lines = colored_message.splitlines()
    new_message = "".join("\n   " + line for line in lines) + "\n"

    return base + new_message

escape

escape(record: dict)

Escape the "<" character before markup parsing

Source code in eds_scikit/utils/logging.py
44
45
46
47
48
49
50
51
def escape(record: dict):
    """
    Escape the "<" character before markup parsing
    """
    return {
        k: v if not isinstance(v, str) else v.replace("<", r"\<")
        for k, v in record.items()
    }
Back to top