Skip to content

Commit c5b5f69

Browse files
committed
refactor: Allow specifying name of template loggers
1 parent 7ff1681 commit c5b5f69

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/mkdocstrings/handlers/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class BaseHandler:
7474
To add custom CSS, add an `extra_css` variable or create an 'style.css' file beside the templates.
7575
"""
7676

77+
# TODO: Make name mandatory?
7778
name: str = ""
7879
"""The handler's name, for example "python"."""
7980
domain: str = "default"
@@ -132,7 +133,7 @@ def __init__(self, handler: str, theme: str, custom_templates: str | None = None
132133
auto_reload=False, # Editing a template in the middle of a build is not useful.
133134
)
134135
self.env.filters["any"] = do_any
135-
self.env.globals["log"] = get_template_logger()
136+
self.env.globals["log"] = get_template_logger(self.name)
136137

137138
self._headings: list[Element] = []
138139
self._md: Markdown = None # type: ignore[assignment] # To be populated in `update_env`.

src/mkdocstrings/loggers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ def get_logger(name: str) -> LoggerAdapter:
177177
return LoggerAdapter(name.split(".", 1)[0], logger)
178178

179179

180-
def get_template_logger() -> TemplateLogger:
180+
def get_template_logger(handler_name: str | None = None) -> TemplateLogger:
181181
"""Return a logger usable in templates.
182182
183+
Parameters:
184+
handler_name: The name of the handler.
185+
183186
Returns:
184187
A template logger.
185188
"""
186-
return TemplateLogger(get_logger("mkdocstrings.templates"))
189+
handler_name = handler_name or "base"
190+
return TemplateLogger(get_logger(f"mkdocstrings_handlers.{handler_name}.templates"))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy