Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transport implementation questions #61

Open
iccicci opened this issue Jun 3, 2020 · 2 comments
Open

Transport implementation questions #61

iccicci opened this issue Jun 3, 2020 · 2 comments

Comments

@iccicci
Copy link

iccicci commented Jun 3, 2020

Hi all,

I'm planning to write a new winston transport; looking at the log method example in the readme it seems that the log method has to fire a logged event, but since I like to understand what I'm writing rather than simply to cut&paste code, I have some question about it.

This is the log method example in the readme:

log(info, callback) {
  setImmediate(() => {
    this.emit('logged', info);
  });

  // Perform the writing to the remote service

  callback();
}
  1. Why should logged event be fired? I would have thought that callback was enough.
  2. Why should it be fired within a setImmediate?
  3. The name is confusing me. I would have expected to fire something like logging before writing data to the remote service and something like logged later. Is it ok that logged event should be fired before writing the data to the remote service?

Thank you,
iCC

@Limsanity
Copy link

Limsanity commented Jan 5, 2021

It seems you don't have to emit the event.
winston use the feature in test file, such as http.test.js.

@ozanbaskan
Copy link

ozanbaskan commented Sep 15, 2022

setImmediate pushes the function to the callback queue, stack is prioritized over callback queue so if you don't use timers to send your logs to a remote service, setImmediate function is most likely to execute last.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants