Skip to content

n-car/node-events-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-events-logger

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.

Install

npm install node-events-logger

Usage

const 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

API

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.

License

MIT © Nicola Carpanese

About

In-memory event logger with ring buffer and real-time access via REST/WebSocket

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors