> -----Original Message-----
> From: Mauro Carvalho Chehab <[email protected]>
> Sent: Tuesday, March 17, 2026 7:10 PM
> To: Jonathan Corbet <[email protected]>; Linux Doc Mailing List <linux-
> [email protected]>
> Cc: Mauro Carvalho Chehab <[email protected]>; linux-
> [email protected]; [email protected]; Loktionov,
> Aleksandr <[email protected]>; Randy Dunlap
> <[email protected]>
> Subject: [PATCH v3 18/22] docs: c_lex: setup a logger to report
> tokenizer issues
> 
> Report file that has issues detected via CMatch and CTokenizer.
> 
> This is done by setting up a logger that will be overriden by
overridden -> overridden

Otherwise, fine
Reviewed-by: Aleksandr Loktionov <[email protected]>

> kdoc_parser, when used on it.
> 
> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
> ---
>  tools/lib/python/kdoc/c_lex.py       | 16 ++++++++++++++++
>  tools/lib/python/kdoc/kdoc_parser.py |  4 +++-
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/lib/python/kdoc/c_lex.py
> b/tools/lib/python/kdoc/c_lex.py index 20e50ff0ecd5..b6d58bd470a9
> 100644
> --- a/tools/lib/python/kdoc/c_lex.py
> +++ b/tools/lib/python/kdoc/c_lex.py
> @@ -22,6 +22,22 @@ from .kdoc_re import KernRe
> 
>  log = logging.getLogger(__name__)
> 
> +def tokenizer_set_log(logger, prefix = ""):
> +    """
> +    Replace the module‑level logger with a LoggerAdapter that
> +    prepends *prefix* to every message.
> +    """
> +    global log
> +
> +    class PrefixAdapter(logging.LoggerAdapter):
> +        """
> +        Ancillary class to set prefix on all message logs.
> +        """
> +        def process(self, msg, kwargs):
> +            return f"{prefix}{msg}", kwargs
> +
> +    # Wrap the provided logger in our adapter
> +    log = PrefixAdapter(logger, {"prefix": prefix})
> 
>  class CToken():
>      """
> diff --git a/tools/lib/python/kdoc/kdoc_parser.py
> b/tools/lib/python/kdoc/kdoc_parser.py
> index efd58c88ff31..f90c6dd0343d 100644
> --- a/tools/lib/python/kdoc/kdoc_parser.py
> +++ b/tools/lib/python/kdoc/kdoc_parser.py
> @@ -13,7 +13,7 @@ import sys
>  import re
>  from pprint import pformat
> 
> -from kdoc.c_lex import CTokenizer
> +from kdoc.c_lex import CTokenizer, tokenizer_set_log
>  from kdoc.kdoc_re import KernRe
>  from kdoc.kdoc_item import KdocItem
> 
> @@ -253,6 +253,8 @@ class KernelDoc:
>          self.config = config
>          self.xforms = xforms
> 
> +        tokenizer_set_log(self.config.log, f"{self.fname}: CMatch: ")
> +
>          # Initial state for the state machines
>          self.state = state.NORMAL
> 
> --
> 2.52.0

Reply via email to