mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
add maxLength to recording
This commit is contained in:
parent
26dcec62f9
commit
cd8b019e3f
@ -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.
|
||||
|
||||
|
||||
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user