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
Prev Previous commit
Fixed bindings
  • Loading branch information
luislobo committed Aug 18, 2019
commit 495135f86c3f748b53d83693b9b1bd8c876a9a71
19 changes: 9 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@ module.exports = function CaptainsLog(overrides) {
// reasonable guesses if the custom logger is missing any
// (only required method is `logger.log` or `logger.debug`)
// If no reasonable alternative is possible, don't log
var nullLog = function() {};

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;
logger.crit = logger.crit ? logger.crit.bind(logger) : logger.error;
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;

logger.debug = logger.debug ? logger.debug.bind(logger) : _.noop;
logger.info = logger.info ? logger.info.bind(logger) : _.noop;
logger.error = logger.error ? logger.error.bind(logger) : _.noop;
logger.warn = logger.warn ? logger.warn.bind(logger) : (logger.error ? logger.error.bind(logger) : _.noop);
logger.crit = logger.crit ? logger.crit.bind(logger) : (logger.error ? logger.error.bind(logger) : _.noop);
logger.verbose = logger.verbose ? logger.verbose.bind(logger) : _.noop;
logger.silly = logger.silly ? logger.silly.bind(logger) : _.noop;
logger.blank = logger.blank ? logger.blank.bind(logger) : _.noop;
}

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