Skip to content

Commit

Permalink
Merge pull request #8033 from Mangosteen-Yang/new-feature-#6403
Browse files Browse the repository at this point in the history
debug support {color: false}
  • Loading branch information
vkarpov15 committed Aug 1, 2019
2 parents f58c45f + e4169a2 commit 4b2f770
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/drivers/node-mongodb-native/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function iter(i) {
} else if (debug instanceof stream.Writable) {
this.$printToStream(_this.name, i, args, debug);
} else {
this.$print(_this.name, i, args);
this.$print(_this.name, i, args, typeof debug.color === 'undefined' ? true : debug.color);
}
}

Expand Down Expand Up @@ -190,13 +190,13 @@ for (const i in Collection.prototype) {
* @method $print
*/

NativeCollection.prototype.$print = function(name, i, args) {
const moduleName = '\x1B[0;36mMongoose:\x1B[0m ';
NativeCollection.prototype.$print = function(name, i, args, color) {
const moduleName = color ? '\x1B[0;36mMongoose:\x1B[0m ' : 'Mongoose: ';
const functionCall = [name, i].join('.');
const _args = [];
for (let j = args.length - 1; j >= 0; --j) {
if (this.$format(args[j]) || _args.length) {
_args.unshift(this.$format(args[j]));
_args.unshift(this.$format(args[j], color));
}
}
const params = '(' + _args.join(', ') + ')';
Expand Down Expand Up @@ -231,10 +231,10 @@ NativeCollection.prototype.$printToStream = function(name, i, args, stream) {
* @method $format
*/

NativeCollection.prototype.$format = function(arg) {
NativeCollection.prototype.$format = function(arg, color) {
const type = typeof arg;
if (type === 'function' || type === 'undefined') return '';
return format(arg);
return format(arg, false, color);
};

/*!
Expand All @@ -259,7 +259,7 @@ function formatObjectId(x, key) {
function formatDate(x, key) {
x[key] = inspectable('new Date("' + x[key].toUTCString() + '")');
}
function format(obj, sub) {
function format(obj, sub, color) {
if (obj && typeof obj.toBSON === 'function') {
obj = obj.toBSON();
}
Expand Down Expand Up @@ -322,7 +322,7 @@ function format(obj, sub) {
}

return util.
inspect(x, false, 10, true).
inspect(x, false, 10, color).
replace(/\n/g, '').
replace(/\s{2,}/g, ' ');
}
Expand Down

0 comments on commit 4b2f770

Please sign in to comment.