1
+ """
2
+ Logger utility
3
+ !!! abstract "Usage Documentation"
4
+ [`Logger`](../../core/logger.md)
5
+ """
1
6
from __future__ import annotations
2
7
3
8
import functools
@@ -82,7 +87,7 @@ class Logger:
82
87
by default "INFO"
83
88
child: bool, optional
84
89
create a child Logger named <service>.<caller_file_name>, False by default
85
- sample_rate : float, optional
90
+ sampling_rate : float, optional
86
91
sample rate for debug calls within execution context defaults to 0.0
87
92
stream: sys.stdout, optional
88
93
valid output for a logging stream, by default sys.stdout
@@ -103,7 +108,6 @@ class Logger:
103
108
use_datetime_directive: bool, optional
104
109
Interpret `datefmt` as a format string for `datetime.datetime.strftime`, rather than
105
110
`time.strftime`.
106
-
107
111
See https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior . This
108
112
also supports a custom %F directive for milliseconds.
109
113
use_rfc3339: bool, optional
@@ -116,7 +120,6 @@ class Logger:
116
120
by default json.loads
117
121
json_default : Callable, optional
118
122
function to coerce unserializable values, by default `str()`
119
-
120
123
Only used when no custom formatter is set
121
124
utc : bool, optional
122
125
set logging timestamp to UTC, by default False to continue to use local time as per stdlib
@@ -590,17 +593,19 @@ def append_context_keys(self, **additional_keys: Any) -> Generator[None, None, N
590
593
"""
591
594
Context manager to temporarily add logging keys.
592
595
593
- Parameters:
596
+ Parameters
594
597
-----------
595
- **keys : Any
598
+ **additional_keys : Any
596
599
Key-value pairs to include in the log context during the lifespan of the context manager.
597
600
598
- Example:
601
+ Example
599
602
--------
600
- >>> logger = Logger(service="example_service")
601
- >>> with logger.append_context_keys(user_id="123", operation="process"):
602
- >>> logger.info("Log with context")
603
- >>> logger.info("Log without context")
603
+ **Logging with contextual keys**
604
+
605
+ logger = Logger(service="example_service")
606
+ with logger.append_context_keys(user_id="123", operation="process"):
607
+ logger.info("Log with context")
608
+ logger.info("Log without context")
604
609
"""
605
610
with self .registered_formatter .append_context_keys (** additional_keys ):
606
611
yield
0 commit comments