Description
Use case
In #3617 we have implemented a mechanism to buffer logs. The next step in the implementation is to make the feature configurable via constructor options.
Solution/User Experience
Customers should be able to configure log buffering via constructor options.
The ConstructorOptions
type/object is already pretty crowded (link), so we should add the new settings as a nested object.
In practice, we should add a new optional bufferConfig
object to ConstructorOptions
and this object should have the following keys all optional:
enabled
: boolean (defaults totrue
)maxBytes
- this allows customers to configure the max size of the buffer in bytes (optional defaults to1024
)flushOnErrorLog
- this allows customers to toggle whether the buffer is flushed when callinglogger.error()
(optional defaults totrue
)bufferAtVerbosity
- this allows customers to configure the threshold at which we'll buffer logs (optional defaults toDEBUG
|debug
, acceptsTRACE
,DEBUG
,INFO
, andWARN
plus their corresponding small case versions - you can never bufferERROR
logs)
The configuration logic of the Logger can be found in the setOptions()
method. The order in which things are initialized in this method matters, but for this feature I can't think of any dependency so I'd just add it at the end here.
To follow the existing pattern, we should add a new #setLogBuffering()
method (feel free to use a better name as long as it starts with the #set
prefix). This method:
- is called only if
ConstructorOptions['bufferConfig']
is present - accepts the
ConstructorOptions['bufferConfig']
object - configures the appropriate fields that were added in feat(logger): Add log buffer and flush method #3617 (we might need to move the instantiation of the
#buffer
here, since the max size is know only at this point)
Then, after this is added, we should also:
- make the
flushBuffer()
method public - add the newly public method to the
LoggerInterface
- modify the
error()
method to flush the buffer if log buffering is enabled &&flushOnErrorLog
istrue
Besides the implementation, we should update the unit tests that use the feature to now use both the public config and new public methods as well as add tests for the new config + flush-on-error behavior. Likewise, we should make sure the new types are added and documented properly (see other types in the same file for reference).
Alternative solutions
N/A
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status