Skip to content

Commit

Permalink
add maxLength to recording
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-cloud committed May 19, 2023
1 parent 26dcec6 commit cd8b019
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/recording.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This appender stores the log events in memory. It is mainly useful for testing (
## Configuration

- `type` - `recording`
- `maxLength` - `integer` (optional, defaults to undefined) - the maximum array length for the recording. If not specified, the array will grow until cleared

There is no other configuration for this appender.

Expand Down
5 changes: 4 additions & 1 deletion lib/appenders/recording.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ const debug = require('debug')('log4js:recording');

const recordedEvents = [];

function configure() {
function configure(config) {
return function (logEvent) {
debug(
`received logEvent, number of events now ${recordedEvents.length + 1}`
);
debug('log event was ', logEvent);
if (config.maxLength && recordedEvents.length >= config.maxLength) {
recordedEvents.shift();
}
recordedEvents.push(logEvent);
};
}
Expand Down

0 comments on commit cd8b019

Please sign in to comment.