Tiny class that stores recent events in memory (ring buffer) and emits an event notification through Node's EventEmitter. Useful for exposing traces over WebSocket/Socket.IO or a simple REST endpoint without pulling a full logging stack.
npm install node-events-loggerconst EventsLogger = require('node-events-logger');
const log = new EventsLogger(50); // keep only the latest 50 events
log.on('event', (evt) => {
console.log(`[trace] ${evt.source}:${evt.name}`, evt.data);
});
log.log('plc', 'connected', { ip: '10.0.0.2' });
console.log(log.events); // copy of the buffer| Method | Description |
|---|---|
constructor(maxLength = 100) |
Creates the ring buffer with a maximum number of entries. |
log(source, name, data) |
Adds an event, trims the buffer, emits 'event'. Throws if source/name are missing. |
get events() |
Returns a shallow copy of the internal array. |
MIT © Nicola Carpanese