question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event emitter -- on logger or transport

See original GitHub issue

I’m having an issue catching ‘logged’ notifications and I’m not sure if I’m doing something wrong because the documentation is a little confusing on this point.

It says the winston.Logger is an EventEmitter:

Each instance of winston.Logger is also an instance of an EventEmitter. A logged event will be raised each time a transport successfully logs a message:

but then show an example of listening to events on a winston.transport:

const transport = new winston.transports.Console();
const logger = winston.createLogger({
  transports: [transport];
});

transport.on('logged', function (info) {
  // `info` log message has now been logged
});

logger.info('CHILL WINSTON!', { seriously: true });

Can (or should) we listen to events on the trasport or the logger?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rogerwebcommented, Oct 11, 2018

I’ve just ran a quick test here and I only could have it working if using the following setup:

  • Event logged
  • Listen on the transport (not on the logger)
  • The transport is other than the Console
0reactions
eladchencommented, Jun 8, 2019

a bit late…

Wouldn’t bubbling the ‘logged’ event from each transport cause several events with same data?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing a custom winston-transport: why to emit logged event?
I would emit the event just in case anyone is listening. I checked winston's roadmap and in version 3.3. 0 the "logged" event...
Read more >
Handling and dispatching events with Node.js - LogRocket Blog
This module includes the EventEmitter class, which is used to raise and handle the events. Almost the whole of the Node.js core API...
Read more >
The synchronous nature of the EventEmitter. Node.js ...
The event emitter executes all callbacks in a synchronous manner. Every time you call a function, its context is pushed on the top...
Read more >
Extending the Event Emitter - YouTube
Get the COMPLETE Course (45% OFF - LIMITED TIME): https://programmingwithmosh.com/courses/nodeSubscribe for more videos: ...
Read more >
mole-rpc-transport-eventemitter - npm package - Snyk
We found that mole-rpc-transport-eventemitter demonstrates a positive version release cadence with at least one new version released in the past ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found