You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
logger.debug("Setting log level to Debug due to sampling rate")
@@ -134,12 +187,8 @@ def __init__(
134
187
f"Expected a float value ranging 0 to 1, but received {self.sampling_rate} instead. Please review POWERTOOLS_LOGGER_SAMPLE_RATE environment variable."# noqa E501
Copy file name to clipboardExpand all lines: docs/content/core/logger.mdx
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -183,6 +183,41 @@ def handler(event, context):
183
183
```
184
184
</details>
185
185
186
+
## Reusing Logger across your code
187
+
188
+
Logger supports inheritance via `child` parameter. This allows you to create multiple Loggers across your code base, and propagate changes such as new keys to all Loggers.
189
+
190
+
```python:title=collect.py
191
+
# POWERTOOLS_SERVICE_NAME: "payment"
192
+
import shared # Creates a child logger named "payment.shared"
In this example, `Logger` will create a parent logger named `payment` and a child logger named `payment.shared`. Any changes in the parent and child `Loggers` will be propagated among them.
214
+
215
+
If you ever forget to use `child` param, we will return an existing `Logger` with the same `service` name.
216
+
217
+
<Notetype="info">
218
+
Child loggers will be named after the following convention <code>service.filename</code>.
219
+
</Note><br/>
220
+
186
221
## Sampling debug logs
187
222
188
223
You can dynamically set a percentage of your logs to **DEBUG** level using `sample_rate` param or via env var `POWERTOOLS_LOGGER_SAMPLE_RATE`.
0 commit comments