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

Improve custom transport exemple #1393

Open
Buzut opened this issue Jul 4, 2018 · 3 comments
Open

Improve custom transport exemple #1393

Buzut opened this issue Jul 4, 2018 · 3 comments

Comments

@Buzut
Copy link

Buzut commented Jul 4, 2018

In Adding Custom Transports code exemple, in the log method, there's no explanation on the purpose of both the callback and setImmediate calls.

log(info, callback) {
    // what is this for? Does Winston need it?
    setImmediate(() => {
      this.emit('logged', info);
    });

    // Perform the writing to the remote service
    callback(); // is it required to include this cb in all transports? Does Winston need it?
  }
@davidbeermann
Copy link

I agree. I also think the example could be improved. Considering the comment // Perform the writing to the remote service I'd assume the remote service is an async call. After looking at other custom transports, shouldn't the example rather read like this?

log(info, callback = () => {}) {
    callRemoteService(info)
        .then(result => {
            callback(null, result);
            this.emit('logged', info);
        })
        .catch(error => {
            callback(error);
            this.emit('error', error);
        })
}

The default value for the callback I found in the transports.File code.

@moose56
Copy link

moose56 commented Oct 3, 2018

Would find this really helpful. The example here is limited as is the example in the https://github.com/winstonjs/winston-transport repository.

Looking through a number of custom transports and no two are the same.

@mustafahoda
Copy link

Looks like Callback Implementation is required. Thanks for mentioning this and bringing up this point

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

4 participants