Skip to content

Commit 39f7510

Browse files
committed
docs: add API docs
1 parent 2f748ed commit 39f7510

File tree

10 files changed

+139
-25
lines changed

10 files changed

+139
-25
lines changed

docs/api/adapters.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Adapters module
2+
3+
::: logging_with_context.adapters

docs/api/filters.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Filters module
2+
3+
::: logging_with_context.filters

docs/api/formatters.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Formatters module
2+
3+
::: logging_with_context.formatters

docs/api/global_context.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Global context module
2+
3+
::: logging_with_context.global_context

docs/api/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# API
2+
3+
::: logging_with_context.adapters
4+
options:
5+
show_source: false
6+
heading_level: 2

mkdocs.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,14 @@ markdown_extensions:
3434
- pymdownx.snippets
3535
# Allow nesting fences, needed for syntax highlight.
3636
- pymdownx.superfences
37+
plugins:
38+
- mkdocstrings:
39+
default_handler: python
40+
nav:
41+
- Introduction: index.md
42+
- howto.md
43+
- API:
44+
- api/global_context.md
45+
- api/adapters.md
46+
- api/formatters.md
47+
- api/filters.md

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dev = [
2323
]
2424
doc = [
2525
"mkdocs-material>=9.5.49",
26+
"mkdocstrings[python]>=0.27.0",
2627
]
2728

2829
[tool.hatch.version]

src/logging_with_context/adapters.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,30 @@ class ContextualAdapter(LoggerAdapter):
1515
1616
Example usage:
1717
18-
Set up everything
19-
20-
>>> import logging
21-
>>> from logging_with_context.adapters import ContextualAdapter
22-
>>> from logging_with_context.formatters import ExtraTextFormatter
23-
>>> logging.basicConfig(level=logging.INFO)
24-
>>> root = logging.getLogger()
25-
26-
To be able to see the context in the interpreter.
27-
28-
>>> root.handlers[0].setFormatter(
29-
... ExtraTextFormatter(parent=root.handlers[0].formatter)
30-
... )
31-
32-
Using the adapter
33-
34-
>>> adapter = ContextualAdapter(root)
35-
>>> with adapter.context({"key": "value"}) as logger:
36-
... logger.info("This contains context")
37-
... root.info("This does not")
38-
INFO:root:This contains context |key="value"|
39-
INFO:root:This does not
18+
```pycon
19+
# Set up everything
20+
21+
>>> import logging
22+
>>> from logging_with_context.adapters import ContextualAdapter
23+
>>> from logging_with_context.formatters import ExtraTextFormatter
24+
>>> logging.basicConfig(level=logging.INFO)
25+
>>> root = logging.getLogger()
26+
27+
# To be able to see the context in the interpreter.
28+
29+
>>> root.handlers[0].setFormatter(
30+
... ExtraTextFormatter(parent=root.handlers[0].formatter)
31+
... )
32+
33+
# Using the adapter
34+
35+
>>> adapter = ContextualAdapter(root)
36+
>>> with adapter.context({"key": "value"}) as logger:
37+
... logger.info("This contains context")
38+
... root.info("This does not")
39+
INFO:root:This contains context |key="value"|
40+
INFO:root:This does not
41+
```
4042
"""
4143

4244
# NOTE: Override the type because Mapping doesn't support union operator

src/logging_with_context/filters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
class FilterWithContextVar(Filter):
1111
"""
1212
Add the values from the current context to all the log messages as `extra` keys.
13+
14+
This class is not meant to be used directly, instead it's used by the
15+
`global_context` module.
1316
"""
1417

1518
_context_var: ContextVar[dict[str, Any]]
1619

1720
def __init__(self, context_var: ContextVar[dict[str, Any]]) -> None:
1821
"""
19-
Constructor..
22+
Constructor.
2023
2124
Parameters:
2225
context_var: The context storage to use.

uv.lock

Lines changed: 81 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)