Configuration options for the logger
Optional[captureThe Symbol.for('nodejs.rejection') method is called in case a
promise rejection happens when emitting an event and
captureRejections is enabled on the emitter.
It is possible to use events.captureRejectionSymbol in
place of Symbol.for('nodejs.rejection').
import { EventEmitter, captureRejectionSymbol } from 'node:events';
class MyClass extends EventEmitter {
constructor() {
super({ captureRejections: true });
}
[captureRejectionSymbol](err, event, ...args) {
console.log('rejection happened for', event, 'with', err, ...args);
this.destroy(err);
}
destroy(err) {
// Tear the resource down here.
}
}
Registers an event listener for the specified event (alias for on).
The type of event to listen for.
This instance for chaining.
Closes the logger, flushes pending logs, and releases resources.
Returns an array listing the events for which the emitter has registered listeners.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
Flushes all pending logs and the sinks' buffers, and waits for completion.
Returns the number of listeners for the specified event.
The type of event.
The event name.
The number of listeners.
Removes an event listener for the specified event (alias for removeListener).
The type of event.
This instance for chaining.
Registers a one-time event listener for the specified event.
The type of event to listen for.
This instance for chaining.
Adds a listener to the beginning of the listeners array for the specified event.
The type of event.
This instance for chaining.
Adds a one-time listener to the beginning of the listeners array for the specified event.
The type of event.
This instance for chaining.
Registers a new sink (logging destination) with the logger.
The factory is serialized and re-evaluated inside the worker, so its body must be self-contained (no module-scoped imports captured by closure).
The logger instance with new type (for chaining)
Removes all listeners, or those of the specified eventName.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter instance was created by some other
component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter, so that calls can be chained.
OptionaleventName: string | symbolBy default EventEmitters will print a warning if more than 10 listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners() method allows the limit to be
modified for this specific EventEmitter instance. The value can be set to
Infinity (or 0) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter, so that calls can be chained.
Creates a new Logger instance with the specified options.