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

Bind the custom logger to the log methods, useful for loggers that use "this" on their own log methods #25

Merged
merged 2 commits into from
Sep 8, 2019

Conversation

luislobo
Copy link
Contributor

Bind the custom logger to the log methods, useful for loggers that use "this" on their own log methods

While using the latest winston 3.2.1, issues arise throwing error self._addDefaultMeta is not a function as reported in balderdashy/sails#4601

This fixes the issue

@luislobo
Copy link
Contributor Author

Probably related to balderdashy/sails#4337

@luislobo
Copy link
Contributor Author

Created a project that uses winston 3.2.1, where the logger is working correctly with the current implementation

https://github.com/luislobo/sails-test-2019

Check https://github.com/luislobo/sails-test-2019/blob/master/config/log.js

Copy link
Member

@mikermcneil mikermcneil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luislobo thank you! Added a couple of notes about .bind() for the fallback log method, and also about falling back to a no-op log method in a couple of cases

index.js Outdated
logger.debug = logger.debug ? logger.debug.bind(logger) : nullLog;
logger.info = logger.info ? logger.info.bind(logger) : nullLog;
logger.error = logger.error ? logger.error.bind(logger) : nullLog;
logger.warn = logger.warn ? logger.warn.bind(logger) : logger.error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we kept the "error" fallback, but lost the nullLog short-circuit here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also missing a .bind right? so like logger.warn? logger.warn.bind(logger) : logger.error? logger.error.bind(logger) : nullLog ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the warn method? well at the time warn is being set, error should be whether the error function if it exists, or the nullLog assigned in the error shortcut, am I correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikermcneil In case you didn't see my comments up there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikermcneil I see what you say, I've added the bindings

index.js Outdated
logger.info = logger.info ? logger.info.bind(logger) : nullLog;
logger.error = logger.error ? logger.error.bind(logger) : nullLog;
logger.warn = logger.warn ? logger.warn.bind(logger) : logger.error;
logger.crit = logger.crit ? logger.crit.bind(logger) : logger.error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here- kept the "error" fallback but lost the nullLog short-circuit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, I think we're losing the bind in our fallback -- maybe it should be logger.crit? logger.crit.bind(logger) : logger.error? logger.error.bind(logger) : nullLog ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikermcneil I see what you say, I've added the bindings

@ryd0rz
Copy link

ryd0rz commented Jun 3, 2019

Anything I can do to help move this PR along? Winston is preferred logging mechanism, and without this PR the latest version of winston not working.

I want to use winston so I can leverage sentry.io

@kierans
Copy link

kierans commented Aug 16, 2019

@luislobo Are you able to tie this off? It would mean so much to a lot of people :)

Copy link
Contributor Author

@luislobo luislobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikermcneil I see what you say, I've added the bindings

@luislobo
Copy link
Contributor Author

@mikermcneil This should be ready to review/merge.

All others, sorry about the delay, as always, open source development time is a luxury only a few can do full time ;)

@kierans
Copy link

kierans commented Aug 28, 2019

@mikermcneil Are you able to look at this/merge it?

Copy link
Member

@rachaelshaw rachaelshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luislobo thanks for making those changes! Looks good

@rachaelshaw rachaelshaw merged commit 0b55a1d into balderdashy:master Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants