|
27 | 27 | from mkdocs.structure.pages import Page
|
28 | 28 | from mkdocs.structure.toc import AnchorLink
|
29 | 29 |
|
30 |
| -log = logging.getLogger(f"mkdocs.plugins.{__name__}") |
| 30 | +try: |
| 31 | + from mkdocs.plugins import get_plugin_logger |
| 32 | + |
| 33 | + log = get_plugin_logger(__name__) |
| 34 | +except ImportError: |
| 35 | + # TODO: remove once support for MkDocs <1.5 is dropped |
| 36 | + log = logging.getLogger(f"mkdocs.plugins.{__name__}") # type: ignore[assignment] |
31 | 37 |
|
32 | 38 |
|
33 | 39 | class AutorefsPlugin(BasePlugin):
|
@@ -126,7 +132,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
|
126 | 132 | Returns:
|
127 | 133 | The modified config.
|
128 | 134 | """
|
129 |
| - log.debug(f"{__name__}: Adding AutorefsExtension to the list") |
| 135 | + log.debug("Adding AutorefsExtension to the list") |
130 | 136 | config["markdown_extensions"].append(AutorefsExtension())
|
131 | 137 | return config
|
132 | 138 |
|
@@ -161,7 +167,7 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str: # noqa:
|
161 | 167 | The same HTML. We only use this hook to map anchors to URLs.
|
162 | 168 | """
|
163 | 169 | if self.scan_toc:
|
164 |
| - log.debug(f"{__name__}: Mapping identifiers to URLs for page {page.file.src_path}") |
| 170 | + log.debug(f"Mapping identifiers to URLs for page {page.file.src_path}") |
165 | 171 | for item in page.toc.items:
|
166 | 172 | self.map_urls(page.url, item)
|
167 | 173 | return html
|
@@ -200,15 +206,13 @@ def on_post_page(self, output: str, page: Page, **kwargs: Any) -> str: # noqa:
|
200 | 206 | Returns:
|
201 | 207 | Modified HTML.
|
202 | 208 | """
|
203 |
| - log.debug(f"{__name__}: Fixing references in page {page.file.src_path}") |
| 209 | + log.debug(f"Fixing references in page {page.file.src_path}") |
204 | 210 |
|
205 | 211 | url_mapper = functools.partial(self.get_item_url, from_url=page.url, fallback=self.get_fallback_anchor)
|
206 | 212 | fixed_output, unmapped = fix_refs(output, url_mapper)
|
207 | 213 |
|
208 | 214 | if unmapped and log.isEnabledFor(logging.WARNING):
|
209 | 215 | for ref in unmapped:
|
210 |
| - log.warning( |
211 |
| - f"{__name__}: {page.file.src_path}: Could not find cross-reference target '[{ref}]'", |
212 |
| - ) |
| 216 | + log.warning(f"{page.file.src_path}: Could not find cross-reference target '[{ref}]'") |
213 | 217 |
|
214 | 218 | return fixed_output
|
0 commit comments