Skip to content

Feature request: allow enabling log buffering via constructor #3634

Closed
@dreamorosi

Description

@dreamorosi

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 to true)
  • maxBytes - this allows customers to configure the max size of the buffer in bytes (optional defaults to 1024)
  • flushOnErrorLog - this allows customers to toggle whether the buffer is flushed when calling logger.error() (optional defaults to true)
  • bufferAtVerbosity - this allows customers to configure the threshold at which we'll buffer logs (optional defaults to DEBUG | debug, accepts TRACE, DEBUG, INFO, and WARN plus their corresponding small case versions - you can never buffer ERROR 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:

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

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

confirmedThe scope is clear, ready for implementationfeature-requestThis item refers to a feature request for an existing or new utilityloggerThis item relates to the Logger Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions