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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ module.exports = function CaptainsLog(overrides) {
// If no reasonable alternative is possible, don't log
var nullLog = function() {};

logger.debug = logger.debug || nullLog;
logger.info = logger.info || nullLog;
logger.warn = logger.warn || logger.error || nullLog;
logger.error = logger.error || nullLog;
logger.crit = logger.crit || logger.error || nullLog;
logger.verbose = logger.verbose || nullLog;
logger.silly = logger.silly || nullLog;
logger.blank = logger.blank || nullLog;
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

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

logger.verbose = logger.verbose ? logger.verbose.bind(logger) : nullLog;
logger.silly = logger.silly ? logger.silly.bind(logger) : nullLog;
logger.blank = logger.blank ? logger.blank.bind(logger) : nullLog;
}

// Make logger callable and stuff (wrap it)
Expand Down