Repository: mondeja/mkdocs-include-markdown-plugin (python)

Issue:
WARNING log variables not binded
The following WARNING is logged, but no variable significant value is shown:

`WARNING -  plugins.mkdocs_include_markdown_plugin: Delimiter {delimiter_name} '{delimiter_value}' of '{directive}' directive at {relative_path}:{line_number} not detected in the file{plural_suffix} {readable_files_to_include}`

So I understand that this warns about a mistake in using include delimiters between importing and imported files, but it is not helpful to locate the issue.

Pull request:
Fix logging variables not included formatting messages
Fixes #183, regression from [v6.0.2](https://github.com/mondeja/mkdocs-include-markdown-plugin/releases/tag/v6.0.2).

Patch:
diff --git a/pyproject.toml b/pyproject.toml
index acfdad7..30a97b8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [project]
 name = "mkdocs-include-markdown-plugin"
-version = "6.0.3"
+version = "6.0.4"
 description = "Mkdocs Markdown includer plugin."
 readme = "README.md"
 license = "Apache-2.0"
@@ -74,7 +74,7 @@ dependencies = ["pytest~=7.0", "coverage~=6.4", "covdefaults"]
 
 [[tool.hatch.envs.tests.matrix]]
 python = ["py38", "py39", "py310", "py311", "py312"]
-mkdocs = ["1.4.0", "1.4.3", "1.5.0", "1.5.1"]
+mkdocs = ["1.4.0", "1.4.3", "1.5.0", "1.5.3"]
 cache = ["yes", "no"]
 
 [tool.hatch.envs.tests.overrides]
@@ -82,7 +82,7 @@ matrix.mkdocs.dependencies = [
   { value = "mkdocs==1.4.0", if = ["1.4.0"] },
   { value = "mkdocs==1.4.3", if = ["1.4.3"] },
   { value = "mkdocs==1.5.0", if = ["1.5.0"] },
-  { value = "mkdocs==1.5.1", if = ["1.5.1"] },
+  { value = "mkdocs==1.5.3", if = ["1.5.3"] },
 ]
 matrix.cache.dependencies = [{ value = "platformdirs", if = ["yes"] }]
 
@@ -148,6 +148,7 @@ select = [
   "COM",
   "SLOT",
 ]
+ignore = ["G004"]
 
 [tool.ruff.pydocstyle]
 convention = "google"
diff --git a/src/mkdocs_include_markdown_plugin/event.py b/src/mkdocs_include_markdown_plugin/event.py
index 5ad7b21..0f2cafe 100644
--- a/src/mkdocs_include_markdown_plugin/event.py
+++ b/src/mkdocs_include_markdown_plugin/event.py
@@ -48,7 +48,9 @@ class Settings:  # noqa: D101
     exclude: list[str] | None
 
 
-logger = logging.getLogger('mkdocs.plugins.mkdocs_include_markdown_plugin')
+# TODO: when Mkdocs < 1.5.0 support is dropped, use
+# mkdocs.plugin.get_plugin_logger
+logger = logging.getLogger('mkdocs.plugins.include_markdown')
 
 
 def lineno_from_content_start(content: str, start: int) -> int:
@@ -276,26 +278,15 @@ def get_file_content(  # noqa: PLR0913, PLR0915
                     markdown,
                     directive_match_start,
                 )
+                relative_path = os.path.relpath(page_src_path, docs_dir)
                 logger.warning(
                     (
-                        "Delimiter {delimiter_name} '{delimiter_value}'"
-                        " of '{directive}' directive at"
-                        ' {relative_path}:{line_number}'
-                        ' not detected in the file{plural_suffix}'
-                        ' {readable_files_to_include}'
+                        f"Delimiter {delimiter_name} '{delimiter_value}'"
+                        " of 'include' directive at"
+                        f' {relative_path}:{lineno}'
+                        f' not detected in the file{plural_suffix}'
+                        f' {readable_files_to_include}'
                     ),
-                    extra={
-                        'delimiter_name': delimiter_name,
-                        'delimiter_value': delimiter_value,
-                        'directive': 'include',
-                        'relative_path': os.path.relpath(
-                            page_src_path,
-                            docs_dir,
-                        ),
-                        'line_number': lineno,
-                        'plural_suffix': plural_suffix,
-                        'readable_files_to_include': readable_files_to_include,
-                    },
                 )
 
         return text_to_include
@@ -586,26 +577,15 @@ def get_file_content(  # noqa: PLR0913, PLR0915
                     markdown,
                     directive_match_start,
                 )
+                relative_path = os.path.relpath(page_src_path, docs_dir)
                 logger.warning(
                     (
-                        "Delimiter {delimiter_name} '{delimiter_value}' of"
-                        " '{directive}' directive at"
-                        ' {relative_path}:{line_number}'
-                        ' not detected in the file{plural_suffix}'
-                        ' {readable_files_to_include}'
+                        f"Delimiter {delimiter_name} '{delimiter_value}' of"
+                        " 'include-markdown' directive at"
+                        f' {relative_path}:{lineno}'
+                        f' not detected in the file{plural_suffix}'
+                        f' {readable_files_to_include}'
                     ),
-                    extra={
-                        'delimiter_name': delimiter_name,
-                        'delimiter_value': delimiter_value,
-                        'directive': 'include-markdown',
-                        'relative_path': os.path.relpath(
-                            page_src_path,
-                            docs_dir,
-                        ),
-                        'line_number': lineno,
-                        'plural_suffix': plural_suffix,
-                        'readable_files_to_include': readable_files_to_include,
-                    },
                 )
 
         return text_to_include


Test patch:
diff --git a/tests/test_unit/test_glob_include.py b/tests/test_unit/test_glob_include.py
index 3040981..10c878f 100644
--- a/tests/test_unit/test_glob_include.py
+++ b/tests/test_unit/test_glob_include.py
@@ -99,46 +99,30 @@ barbaz
 %}
 ''',
             [
-                {
-                    'delimiter_name': 'start',
-                    'delimiter_value': '<!-- start-not-found-2 -->',
-                    'relative_path': '{includer_file}',
-                    'line_number': 3,
-                    'plural_suffix': 's',
-                    'readable_files_to_include': (
-                        '{included_file_01}, {included_file_02}'
-                    ),
-                },
-                {
-                    'delimiter_name': 'end',
-                    'delimiter_value': '<!-- end-not-found-2 -->',
-                    'relative_path': '{includer_file}',
-                    'line_number': 3,
-                    'plural_suffix': 's',
-                    'readable_files_to_include': (
-                        '{included_file_01}, {included_file_02}'
-                    ),
-                },
-                {
-                    'delimiter_name': 'start',
-                    'delimiter_value': '<!-- start-not-found-1 -->',
-                    'relative_path': '{includer_file}',
-                    'line_number': 10,
-                    'plural_suffix': 's',
-                    'readable_files_to_include': (
-                        '{included_file_01}, {included_file_02}'
-                    ),
-                },
-                {
-                    'delimiter_name': 'end',
-                    'delimiter_value': '<!-- end-not-found-1 -->',
-                    'relative_path': '{includer_file}',
-                    'line_number': 10,
-                    'plural_suffix': 's',
-                    'readable_files_to_include': (
-                        '{included_file_01}, {included_file_02}'
-                    ),
-                },
+                (
+                    "Delimiter end '<!-- end-not-found-1 -->'"
+                    " of '{directive}' directive"
+                    ' at {includer_file}:10 not detected in'
+                    ' the files {included_file_01}, {included_file_02}'
+                ),
+                (
+                    "Delimiter end '<!-- end-not-found-2 -->'"
+                    " of '{directive}' directive"
+                    ' at {includer_file}:3 not detected in'
+                    ' the files {included_file_01}, {included_file_02}'
+                ),
+                (
+                    "Delimiter start '<!-- start-not-found-1 -->'"
+                    " of '{directive}' directive"
+                    ' at {includer_file}:10 not detected in'
+                    ' the files {included_file_01}, {included_file_02}'
+                ),
+                (
+                    "Delimiter start '<!-- start-not-found-2 -->'"
+                    " of '{directive}' directive"
+                    ' at {includer_file}:3 not detected in'
+                    ' the files {included_file_01}, {included_file_02}'
+                ),
             ],
             id='start-end-not-found',
         ),
@@ -149,9 +133,9 @@ def test_glob_include(
     directive,
     expected_warnings_schemas,
     page,
+    plugin,
     caplog,
     tmp_path,
-    plugin,
 ):
     includer_file = tmp_path / 'includer.txt'
     included_01_file = tmp_path / 'included_01.txt'
@@ -185,22 +169,20 @@ This 02 must appear only without specifying end.
 
     # assert warnings
     expected_warnings_schemas = expected_warnings_schemas or []
-    for warning in expected_warnings_schemas:
-        warning['directive'] = directive
-        warning['relative_path'] = warning['relative_path'].replace(
-            '{includer_file}', str(includer_file.relative_to(tmp_path)),
-        )
-        warning['readable_files_to_include'] = warning[
-            'readable_files_to_include'
-        ].replace(
+    expected_warnings = [
+        msg_schema.replace(
+            '{includer_file}',
+            str(includer_file.relative_to(tmp_path)),
+        ).replace(
             '{included_file_01}',
             str(included_01_file.relative_to(tmp_path)),
         ).replace(
             '{included_file_02}',
             str(included_02_file.relative_to(tmp_path)),
-        )
+        ).replace('{directive}', directive)
+        for msg_schema in expected_warnings_schemas
+    ]
 
-    for i, warning in enumerate(expected_warnings_schemas):
-        for key in warning:
-            assert getattr(caplog.records[i], key) == warning[key]
+    for record in caplog.records:
+        assert record.msg in expected_warnings
     assert len(expected_warnings_schemas) == len(caplog.records)
diff --git a/tests/test_unit/test_include.py b/tests/test_unit/test_include.py
index 988f88e..9563947 100644
--- a/tests/test_unit/test_include.py
+++ b/tests/test_unit/test_include.py
@@ -192,13 +192,11 @@ Some text
 
 ''',
             [
-                {
-                    'delimiter_name': 'start',
-                    'delimiter_value': '<!--start-->',
-                    'relative_path': '{includer_file}',
-                    'line_number': 3,
-                    'readable_files_to_include': '{included_file}',
-                },
+                (
+                    "Delimiter start '<!--start-->' of 'include'"
+                    ' directive at {filepath}:3'
+                    ' not detected in the file {included_file}'
+                ),
             ],
             id='start=foo (not found)-end=None',
         ),
@@ -219,14 +217,11 @@ Some text
 Some text
 ''',
             [
-                {
-                    'delimiter_name': 'end',
-                    'delimiter_value': '<!--end-->',
-                    'relative_path': '{includer_file}',
-                    'line_number': 2,
-                    'readable_files_to_include': '{included_file}',
-                    'directive': 'include',
-                },
+                (
+                    "Delimiter end '<!--end-->' of 'include'"
+                    ' directive at {filepath}:2'
+                    ' not detected in the file {included_file}'
+                ),
             ],
             id='start=None-end=foo (not found)',
         ),
@@ -370,9 +365,9 @@ def test_include(
     expected_result,
     expected_warnings_schemas,
     page,
+    plugin,
     caplog,
     tmp_path,
-    plugin,
 ):
     included_file = tmp_path / 'included.md'
     includer_file = tmp_path / 'includer.md'
@@ -394,17 +389,16 @@ def test_include(
 
     # assert warnings
     expected_warnings_schemas = expected_warnings_schemas or []
-    for warning in expected_warnings_schemas:
-        warning['directive'] = 'include'
-        warning['relative_path'] = str(includer_file.relative_to(tmp_path))
-        warning['readable_files_to_include'] = warning[
-            'readable_files_to_include'
-        ].replace(
+    expected_warnings = [
+        msg_schema.replace(
+            '{filepath}',
+            str(includer_file.relative_to(tmp_path)),
+        ).replace(
             '{included_file}',
             str(included_file.relative_to(tmp_path)),
-        )
+        ) for msg_schema in expected_warnings_schemas
+    ]
 
-    for i, warning in enumerate(expected_warnings_schemas):
-        for key in warning:
-            assert getattr(caplog.records[i], key) == warning[key]
+    for record in caplog.records:
+        assert record.msg in expected_warnings
     assert len(expected_warnings_schemas) == len(caplog.records)
diff --git a/tests/test_unit/test_include_markdown.py b/tests/test_unit/test_include_markdown.py
index 2be8ea5..30b6066 100644
--- a/tests/test_unit/test_include_markdown.py
+++ b/tests/test_unit/test_include_markdown.py
@@ -281,13 +281,11 @@ Some text
             '''# Header
 ''',
             [
-                {
-                    'delimiter_name': 'start',
-                    'delimiter_value': '<!--start-->',
-                    'relative_path': '{filepath}',
-                    'readable_files_to_include': '{included_file}',
-                    'line_number': 2,
-                },
+                (
+                    "Delimiter start '<!--start-->' of 'include-markdown'"
+                    ' directive at {filepath}:2 not detected in the file'
+                    ' {included_file}'
+                ),
             ],
             id='start=foo (not found)-end=None',
         ),
@@ -308,13 +306,11 @@ Some text
 Some text
 ''',
             [
-                {
-                    'delimiter_name': 'end',
-                    'delimiter_value': '<!--end-->',
-                    'relative_path': '{filepath}',
-                    'readable_files_to_include': '{included_file}',
-                    'line_number': 2,
-                },
+                (
+                    "Delimiter end '<!--end-->' of 'include-markdown'"
+                    ' directive at {filepath}:2'
+                    ' not detected in the file {included_file}'
+                ),
             ],
             id='start=None-end=foo (not found)',
         ),
@@ -743,7 +739,6 @@ It is a code block
 
 With some text after it
 ''',
-            # ruff: noqa: ISC003  TODO: error in ruff
             '''1.  This is the first number line
 
 1.  <!-- BEGIN INCLUDE {filepath} -->
@@ -759,7 +754,7 @@ With some text after it
     <!-- END INCLUDE -->
 
 1.  If everything works as expected this should be number 3
-''',
+''',  # noqa: ISC003
             [],
             id='include-code-block-to-list-item (#123)',
         ),
@@ -771,9 +766,9 @@ def test_include_markdown(
     expected_result_schema,
     expected_warnings_schemas,
     page,
+    plugin,
     caplog,
     tmp_path,
-    plugin,
 ):
     included_file = tmp_path / 'included.md'
     includer_file = tmp_path / 'includer.md'
@@ -803,22 +798,18 @@ def test_include_markdown(
 
     # assert warnings
     expected_warnings_schemas = expected_warnings_schemas or []
-    for warning in expected_warnings_schemas:
-        warning['directive'] = 'include-markdown'
-        warning['relative_path'] = warning['relative_path'].replace(
+    expected_warnings = [
+        msg_schema.replace(
             '{filepath}',
             str(includer_file.relative_to(tmp_path)),
-        )
-        warning['readable_files_to_include'] = (
-            warning['readable_files_to_include'].replace(
-                '{included_file}',
-                str(included_file.relative_to(tmp_path)),
-            )
-        )
-
-    for i, warning in enumerate(expected_warnings_schemas):
-        for key in warning:
-            assert getattr(caplog.records[i], key) == warning[key]
+        ).replace(
+            '{included_file}',
+            str(included_file.relative_to(tmp_path)),
+        ) for msg_schema in expected_warnings_schemas
+    ]
+
+    for record in caplog.records:
+        assert record.msg in expected_warnings
     assert len(expected_warnings_schemas) == len(caplog.records)
 
 
@@ -826,8 +817,8 @@ def test_include_markdown(
 def test_include_markdown_relative_rewrite(
     page,
     tmp_path,
-    plugin,
     rewrite_relative_urls,
+    plugin,
 ):
     option_value = '' if rewrite_relative_urls is None else (
         'rewrite-relative-urls=' + rewrite_relative_urls
diff --git a/tests/test_unit/test_logging.py b/tests/test_unit/test_logging.py
index 7fdb464..cb180d1 100644
--- a/tests/test_unit/test_logging.py
+++ b/tests/test_unit/test_logging.py
@@ -47,10 +47,8 @@ Included content
         includer_content, page(includer_file), tmp_path, plugin,
     ) == expected_result
 
-    rec = caplog.records[0]
-    assert rec.delimiter_name == missing_argument
-    assert rec.delimiter_value == f'<!--{missing_argument}-->'
-    assert rec.directive == directive
-    assert rec.relative_path == includer_file_name
-    assert rec.line_number == 3
-    assert rec.readable_files_to_include == included_file_name
+    assert (
+        f"Delimiter {missing_argument} '<!--{missing_argument}-->' of"
+        f" '{directive}' directive at {includer_file_name}:3"
+        f' not detected in the file {included_file_name}'
+    ) in caplog.text
diff --git a/tests/test_unit/test_nested_includes.py b/tests/test_unit/test_nested_includes.py
index 6525e2a..c2689c4 100644
--- a/tests/test_unit/test_nested_includes.py
+++ b/tests/test_unit/test_nested_includes.py
@@ -171,22 +171,16 @@ Some test from final included.
 
 ''',
             [
-                {
-                    'delimiter_name': 'start',
-                    'delimiter_value': '<!--start-->',
-                    'relative_path': '{first_includer_file}',
-                    'line_number': 3,
-                    'readable_files_to_include': '{second_includer_file}',
-                    'directive': 'include-markdown',
-                },
-                {
-                    'delimiter_name': 'end',
-                    'delimiter_value': '<!--end-->',
-                    'relative_path': '{first_includer_file}',
-                    'line_number': 3,
-                    'readable_files_to_include': '{second_includer_file}',
-                    'directive': 'include-markdown',
-                },
+                (
+                    "Delimiter start '<!--start-->' of 'include-markdown'"
+                    ' directive at {first_includer_file}:3 not detected'
+                    ' in the file {second_includer_file}'
+                ),
+                (
+                    "Delimiter end '<!--end-->' of 'include-markdown'"
+                    ' directive at {first_includer_file}:3 not detected'
+                    ' in the file {second_includer_file}'
+                ),
             ],
             id='start-end-not-found (first-level)',
         ),
@@ -219,22 +213,16 @@ Included content
 Included content
 ''',
             [
-                {
-                    'delimiter_name': 'start',
-                    'delimiter_value': '<!--start-->',
-                    'relative_path': '{second_includer_file}',
-                    'line_number': 3,
-                    'readable_files_to_include': '{included_file}',
-                    'directive': 'include-markdown',
-                },
-                {
-                    'delimiter_name': 'end',
-                    'delimiter_value': '<!--end-->',
-                    'relative_path': '{second_includer_file}',
-                    'line_number': 3,
-                    'readable_files_to_include': '{included_file}',
-                    'directive': 'include-markdown',
-                },
+                (
+                    "Delimiter start '<!--start-->' of 'include-markdown'"
+                    ' directive at {second_includer_file}:3 not detected'
+                    ' in the file {included_file}'
+                ),
+                (
+                    "Delimiter end '<!--end-->' of 'include-markdown'"
+                    ' directive at {second_includer_file}:3 not detected'
+                    ' in the file {included_file}'
+                ),
             ],
             id='start-end-not-found (second-level)',
         ),
@@ -247,9 +235,9 @@ def test_nested_include(
     expected_result,
     expected_warnings_schemas,
     page,
+    plugin,
     caplog,
     tmp_path,
-    plugin,
 ):
     first_includer_file = tmp_path / 'first-includer.txt'
     second_includer_file = tmp_path / 'second-includer.txt'
@@ -273,24 +261,21 @@ def test_nested_include(
 
     # assert warnings
     expected_warnings_schemas = expected_warnings_schemas or []
-    for warning in expected_warnings_schemas:
-        warning['relative_path'] = warning['relative_path'].replace(
+    expected_warnings = [
+        msg_schema.replace(
             '{first_includer_file}',
             str(first_includer_file.relative_to(tmp_path)),
         ).replace(
             '{second_includer_file}',
             str(second_includer_file.relative_to(tmp_path)),
-        )
-        warning['readable_files_to_include'] = warning[
-            'readable_files_to_include'
-        ].replace(
-            '{second_includer_file}',
-            str(second_includer_file.relative_to(tmp_path)),
-        ).replace('{included_file}', str(included_file.relative_to(tmp_path)))
+        ).replace(
+            '{included_file}',
+            str(included_file.relative_to(tmp_path)),
+        ) for msg_schema in expected_warnings_schemas
+    ]
 
-    for i, warning in enumerate(expected_warnings_schemas):
-        for key in warning:
-            assert getattr(caplog.records[i], key) == warning[key]
+    for record in caplog.records:
+        assert record.msg in expected_warnings
     assert len(expected_warnings_schemas) == len(caplog.records)