|
2 | 2 | # # Note: Edits to hooks do not get captured by MkDocs' built-in reloading mechanism. |
3 | 3 | # If you change the hooks, you must manually stop and restart the server. |
4 | 4 | import copy |
| 5 | +import logging |
5 | 6 | import re |
6 | 7 | from pathlib import Path |
7 | 8 | from typing import List, Optional, TypedDict |
|
12 | 13 | from parsers.cnrecs import Field, FieldGroup, Record, RecordsParser |
13 | 14 | from slugify import slugify |
14 | 15 |
|
| 16 | +root_logger = logging.getLogger("mkdocs") |
| 17 | + |
| 18 | + |
| 19 | +def on_startup(command, dirty): |
| 20 | + class SuppressAutorefsWarnings(logging.Filter): |
| 21 | + def filter(self, record): |
| 22 | + message = record.getMessage() |
| 23 | + should_suppress = record.levelno == logging.WARNING and ( |
| 24 | + message.startswith("mkdocs_autorefs: Multiple primary URLs found for") |
| 25 | + or message.startswith("mkdocs_autorefs: Could not find closest primary URL") |
| 26 | + ) |
| 27 | + return not should_suppress |
| 28 | + |
| 29 | + # Autorefs uses several loggers, including _internal ones. Since I couldn't figure |
| 30 | + # out which logger was responsible for issuing the warnings we want to suppress, |
| 31 | + # simply attach the filter to all loggers that are part of the plugin. |
| 32 | + autorefs_loggers = [ |
| 33 | + logging.getLogger(path) |
| 34 | + for path in list(logging.root.manager.loggerDict.keys()) |
| 35 | + if path.startswith("mkdocs.plugins.mkdocs_autorefs") |
| 36 | + ] |
| 37 | + |
| 38 | + for logger in autorefs_loggers: |
| 39 | + logger.addFilter(SuppressAutorefsWarnings()) |
| 40 | + |
15 | 41 |
|
16 | 42 | class RecordPrefixClass(TypedDict, total=False): |
17 | 43 | value: str |
|
0 commit comments