Skip to content

Commit cd8b019

Browse files
committed
add maxLength to recording
1 parent 26dcec6 commit cd8b019

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

docs/recording.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This appender stores the log events in memory. It is mainly useful for testing (
55
## Configuration
66

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

910
There is no other configuration for this appender.
1011

lib/appenders/recording.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ const debug = require('debug')('log4js:recording');
22

33
const recordedEvents = [];
44

5-
function configure() {
5+
function configure(config) {
66
return function (logEvent) {
77
debug(
88
`received logEvent, number of events now ${recordedEvents.length + 1}`
99
);
1010
debug('log event was ', logEvent);
11+
if (config.maxLength && recordedEvents.length >= config.maxLength) {
12+
recordedEvents.shift();
13+
}
1114
recordedEvents.push(logEvent);
1215
};
1316
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy