Skip to content

Commit 36b7aff

Browse files
docs(api): migrating the logger utility to mkdocstrings (#6021)
Mkdocstrings - Logging
1 parent 1c77dec commit 36b7aff

File tree

9 files changed

+41
-17
lines changed

9 files changed

+41
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class InvalidLoggerSamplingRateError(Exception):
2+
"""
3+
Logger configured with Invalid Sampling value
4+
"""
25
pass

aws_lambda_powertools/logging/formatter.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,17 @@ def append_context_keys(self, **additional_keys: Any) -> Generator[None, None, N
273273
"""
274274
Context manager to temporarily add logging keys.
275275
276-
Parameters:
276+
Parameters
277277
-----------
278-
**keys: Any
278+
**additional_keys: Any
279279
Key-value pairs to include in the log context during the lifespan of the context manager.
280280
281-
Example:
281+
Example
282282
--------
283-
>>> logger = Logger(service="example_service")
284-
>>> with logger.append_context_keys(user_id="123", operation="process"):
285-
>>> logger.info("Log with context")
286-
>>> logger.info("Log without context")
283+
logger = Logger(service="example_service")
284+
with logger.append_context_keys(user_id="123", operation="process"):
285+
logger.info("Log with context")
286+
logger.info("Log without context")
287287
"""
288288
# Add keys to the context
289289
self.append_keys(**additional_keys)

aws_lambda_powertools/logging/logger.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Logger utility
3+
!!! abstract "Usage Documentation"
4+
[`Logger`](../../core/logger.md)
5+
"""
16
from __future__ import annotations
27

38
import functools
@@ -82,7 +87,7 @@ class Logger:
8287
by default "INFO"
8388
child: bool, optional
8489
create a child Logger named <service>.<caller_file_name>, False by default
85-
sample_rate: float, optional
90+
sampling_rate: float, optional
8691
sample rate for debug calls within execution context defaults to 0.0
8792
stream: sys.stdout, optional
8893
valid output for a logging stream, by default sys.stdout
@@ -103,7 +108,6 @@ class Logger:
103108
use_datetime_directive: bool, optional
104109
Interpret `datefmt` as a format string for `datetime.datetime.strftime`, rather than
105110
`time.strftime`.
106-
107111
See https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior . This
108112
also supports a custom %F directive for milliseconds.
109113
use_rfc3339: bool, optional
@@ -116,7 +120,6 @@ class Logger:
116120
by default json.loads
117121
json_default : Callable, optional
118122
function to coerce unserializable values, by default `str()`
119-
120123
Only used when no custom formatter is set
121124
utc : bool, optional
122125
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
590593
"""
591594
Context manager to temporarily add logging keys.
592595
593-
Parameters:
596+
Parameters
594597
-----------
595-
**keys: Any
598+
**additional_keys: Any
596599
Key-value pairs to include in the log context during the lifespan of the context manager.
597600
598-
Example:
601+
Example
599602
--------
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")
604609
"""
605610
with self.registered_formatter.append_context_keys(**additional_keys):
606611
yield
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- markdownlint-disable MD043 MD041 -->
2+
::: aws_lambda_powertools.logging.formatters.datadog

docs/api_doc/logger/exceptions.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- markdownlint-disable MD043 MD041 -->
2+
::: aws_lambda_powertools.logging.exceptions

docs/api_doc/logger/formatter.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- markdownlint-disable MD043 MD041 -->
2+
::: aws_lambda_powertools.logging.formatter

docs/api_doc/logger/lambda_context.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- markdownlint-disable MD043 MD041 -->
2+
::: aws_lambda_powertools.logging.lambda_context

docs/api_doc/logger/logger.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- markdownlint-disable MD043 MD041 -->
2+
::: aws_lambda_powertools.logging.logger

mkdocs.yml

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ nav:
8686
- Persistence: api_doc/idempotency/persistence.md
8787
- Serialization: api_doc/idempotency/serialization.md
8888
- JMESPath Functions: api_doc/jmespath_functions.md
89+
- Logger:
90+
- DataDog Formatter: api_doc/logger/datadog_formatter.md
91+
- Exceptions: api_doc/logger/exceptions.md
92+
- Formatter: api_doc/logger/formatter.md
93+
- Lambda Context: api_doc/logger/lambda_context.md
94+
- Logger: api_doc/logger/logger.md
8995
- Middleware Factory: api_doc/middleware_factory.md
9096
- Parameters:
9197
- Base: api_doc/parameters/base.md

0 commit comments

Comments
 (0)