Skip to content

Commit feb7f86

Browse files
committed
Indent log message
Instead of having this: ``` WARNING - Mismatched weight for 'Segoe Script' (requested weight 100-Thin, got 400-Regular). Used on lines: 1 ``` We now have this: ``` WARNING - Mismatched weight for 'Segoe Script' (requested weight 100-Thin, got 400-Regular). Used on lines: 1 ```
1 parent 56c2806 commit feb7f86

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

font_collector/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,26 @@
1010
from ._version import __version__
1111
from fontTools.misc.loggingTools import configLogger
1212

13+
14+
class IndentMultilineFormatter(logging.Formatter):
15+
def __init__(self):
16+
super().__init__("%(levelname)s - %(message)s")
17+
18+
def format(self, record):
19+
s = super().format(record)
20+
head, *tail = s.splitlines()
21+
indent = " " * (len(record.levelname) + 3) # "LEVEL - " length
22+
s = "\n".join([head] + [indent + line for line in tail])
23+
return s
24+
25+
1326
configLogger(level="CRITICAL")
1427

1528
# Set our default logger
1629
_logger = logging.getLogger(__name__)
1730
_logger.setLevel(logging.INFO)
1831

19-
_formatter = logging.Formatter("%(levelname)s - %(message)s")
32+
_formatter = IndentMultilineFormatter()
2033

2134
_handler = logging.StreamHandler()
2235
_handler.setLevel(logging.INFO)

font_collector/__main__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,24 @@ def main() -> None:
6161
# Did not found the font
6262
if font_result is None:
6363
nbr_font_not_found += 1
64-
_logger.error(f"Could not find font '{style.fontname}'")
65-
_logger.error(f"Used on lines: {' '.join(str(line) for line in usage_data.ordered_lines)}")
64+
_logger.error(
65+
f"Could not find font '{style.fontname}'\n"
66+
f"Used on lines: {' '.join(str(line) for line in usage_data.ordered_lines)}"
67+
)
6668
else:
69+
log_msg = ""
6770
if font_result.need_faux_bold:
68-
_logger.warning(f"Faux bold used for '{style.fontname}' (requested weight {style.weight}-{(font_weight_to_name(style.weight))}, got {font_result.font_face.weight}-{(font_weight_to_name(font_result.font_face.weight))}).")
71+
log_msg = f"Faux bold used for '{style.fontname}' (requested weight {style.weight}-{(font_weight_to_name(style.weight))}, got {font_result.font_face.weight}-{(font_weight_to_name(font_result.font_face.weight))})."
6972
elif font_result.mismatch_bold:
70-
_logger.warning(f"Mismatched weight for '{style.fontname}' (requested weight {style.weight}-{(font_weight_to_name(style.weight))}, got {font_result.font_face.weight}-{(font_weight_to_name(font_result.font_face.weight))}).")
73+
log_msg = f"Mismatched weight for '{style.fontname}' (requested weight {style.weight}-{(font_weight_to_name(style.weight))}, got {font_result.font_face.weight}-{(font_weight_to_name(font_result.font_face.weight))})."
7174
if font_result.mismatch_italic:
72-
_logger.warning(f"Mismatched italic for '{style.fontname}' (requested {'non-' if style.italic else ''}italic, got {'non-' if font_result.font_face.is_italic else ''}italic).")
75+
log_msg = f"Mismatched italic for '{style.fontname}' (requested {'non-' if style.italic else ''}italic, got {'non-' if font_result.font_face.is_italic else ''}italic)."
7376

74-
if font_result.need_faux_bold or font_result.mismatch_bold or font_result.mismatch_italic:
75-
_logger.warning(f"Used on lines: {' '.join(str(line) for line in usage_data.ordered_lines)}")
77+
if log_msg:
78+
_logger.warning(
79+
f"{log_msg}\n"
80+
f"Used on lines: {' '.join(str(line) for line in usage_data.ordered_lines)}"
81+
)
7682

7783

7884
missing_glyphs = font_result.font_face.get_missing_glyphs(usage_data.characters_used)

0 commit comments

Comments
 (0)