Skip to content

Commit ca8d758

Browse files
committed
refactor: Use new MkDocs plugin logger if available
1 parent 94b4af6 commit ca8d758

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/mkdocs_autorefs/plugin.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
from mkdocs.structure.pages import Page
2828
from mkdocs.structure.toc import AnchorLink
2929

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]
3137

3238

3339
class AutorefsPlugin(BasePlugin):
@@ -126,7 +132,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
126132
Returns:
127133
The modified config.
128134
"""
129-
log.debug(f"{__name__}: Adding AutorefsExtension to the list")
135+
log.debug("Adding AutorefsExtension to the list")
130136
config["markdown_extensions"].append(AutorefsExtension())
131137
return config
132138

@@ -161,7 +167,7 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str: # noqa:
161167
The same HTML. We only use this hook to map anchors to URLs.
162168
"""
163169
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}")
165171
for item in page.toc.items:
166172
self.map_urls(page.url, item)
167173
return html
@@ -200,15 +206,13 @@ def on_post_page(self, output: str, page: Page, **kwargs: Any) -> str: # noqa:
200206
Returns:
201207
Modified HTML.
202208
"""
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}")
204210

205211
url_mapper = functools.partial(self.get_item_url, from_url=page.url, fallback=self.get_fallback_anchor)
206212
fixed_output, unmapped = fix_refs(output, url_mapper)
207213

208214
if unmapped and log.isEnabledFor(logging.WARNING):
209215
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}]'")
213217

214218
return fixed_output

0 commit comments

Comments
 (0)