Skip to content

Commit d24a258

Browse files
Adding new parameter to the constructor
1 parent ebf49db commit d24a258

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

aws_lambda_powertools/logging/buffer/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import Literal
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from aws_lambda_powertools.logging.types import LOG_LEVEL_VALUES
47

58

69
class LoggerBufferConfig:
@@ -14,7 +17,7 @@ class LoggerBufferConfig:
1417
def __init__(
1518
self,
1619
max_size: int = 10240,
17-
minimum_log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "DEBUG",
20+
minimum_log_level: LOG_LEVEL_VALUES = "DEBUG",
1821
flush_on_error: bool = True,
1922
compress: bool = False,
2023
):

aws_lambda_powertools/logging/logger.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from contextlib import contextmanager
1717
from typing import IO, TYPE_CHECKING, Any, Callable, Generator, Iterable, Mapping, TypeVar, overload
1818

19+
from aws_lambda_powertools.logging.buffer.cache import LoggerBufferCache
1920
from aws_lambda_powertools.logging.constants import (
2021
LOGGER_ATTRIBUTE_PRECONFIGURED,
2122
)
@@ -36,8 +37,11 @@
3637
from aws_lambda_powertools.utilities import jmespath_utils
3738

3839
if TYPE_CHECKING:
40+
from aws_lambda_powertools.logging.buffer.config import LoggerBufferConfig
41+
from aws_lambda_powertools.logging.types import LOG_LEVEL_VALUES
3942
from aws_lambda_powertools.shared.types import AnyCallableT
4043

44+
4145
logger = logging.getLogger(__name__)
4246

4347
is_cold_start = True
@@ -82,7 +86,7 @@ class Logger:
8286
----------
8387
service : str, optional
8488
service name to be appended in logs, by default "service_undefined"
85-
level : str, int optional
89+
level : Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], int optional
8690
The level to set. Can be a string representing the level name: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'
8791
or an integer representing the level value: 10 for 'DEBUG', 20 for 'INFO', 30 for 'WARNING', 40 for 'ERROR', 50 for 'CRITICAL'.
8892
by default "INFO"
@@ -200,7 +204,7 @@ class Logger:
200204
def __init__(
201205
self,
202206
service: str | None = None,
203-
level: str | int | None = None,
207+
level: LOG_LEVEL_VALUES | int | None = None,
204208
child: bool = False,
205209
sampling_rate: float | None = None,
206210
stream: IO[str] | None = None,
@@ -216,6 +220,7 @@ def __init__(
216220
utc: bool = False,
217221
use_rfc3339: bool = False,
218222
serialize_stacktrace: bool = True,
223+
logger_buffer: LoggerBufferConfig | None = None,
219224
**kwargs,
220225
) -> None:
221226
self.service = resolve_env_var_choice(
@@ -252,6 +257,10 @@ def __init__(
252257
"serialize_stacktrace": serialize_stacktrace,
253258
}
254259

260+
self._logger_buffer = logger_buffer
261+
if self._logger_buffer:
262+
self._buffer_cache = LoggerBufferCache(max_size_bytes=self._logger_buffer.max_size)
263+
255264
self._init_logger(formatter_options=formatter_options, log_level=level, **kwargs)
256265

257266
if self.log_uncaught_exceptions:

aws_lambda_powertools/logging/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any, Dict, TypedDict, Union
3+
from typing import TYPE_CHECKING, Any, Dict, Literal, TypedDict, Union
44

55
if TYPE_CHECKING:
66
from typing_extensions import NotRequired, TypeAlias
77

8+
LOG_LEVEL_VALUES = Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
9+
810

911
class PowertoolsLogRecord(TypedDict):
1012
# Base fields (required)

0 commit comments

Comments
 (0)