@@ -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
0 commit comments