Skip to content

Commit

Permalink
fix: correctly pass arguments to debug calls
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Nov 1, 2018
1 parent 6d1406c commit 5146812
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/util/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@ const debug = Debug('couch:debug');
const trace = Debug('couch:trace');

module.exports = function (prefix) {
const func = (...args) => debug(`(${prefix}) ${processArgs(args)}`);
func.error = (...args) => error(`(${prefix}) ${processArgs(args)}`);
func.warn = (...args) => warn(`(${prefix}) ${processArgs(args)}`);
const func = (message, ...args) => debug(`(${prefix}) ${message}`, ...args);
func.error = (message, ...args) => error(`(${prefix}) ${message}`, ...args);
func.warn = (message, ...args) => warn(`(${prefix}) ${message}`, ...args);
func.debug = func;
func.trace = (...args) => trace(`(${prefix}) ${processArgs(args)}`);
func.trace = (message, ...args) => trace(`(${prefix}) ${message}`, ...args);
return func;
};

function processArgs(args) {
args = args.map((arg) => {
if (arg instanceof Error) {
return `${arg.message}\n${arg.stack}`;
}
return arg;
});
return args.join('\n');
}

0 comments on commit 5146812

Please sign in to comment.