1
0
Fork 0

More meaningful object logging

Don't log inherited attributes.
Do log constructor name for class instances.
Use _PRINT methods if available except when using console.dir.
This commit is contained in:
Alan Plum 2017-05-30 20:09:22 +02:00
parent ab177612a5
commit 23ac54183c
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
2 changed files with 6 additions and 11 deletions

View File

@ -104,6 +104,7 @@ global.DEFINE_MODULE('console', (function () {
arg = String(arg);
} else if (Object.prototype.isPrototypeOf(arg) || Array.isArray(arg)) {
arg = inspect(arg, {
customInspect: true,
prettyPrint: false
});
}

View File

@ -1121,13 +1121,11 @@ global.DEFINE_MODULE('internal', (function () {
var keys;
try {
keys = Object.keys(object);
// try to detect an ES6 class. note that this won't work 100% correct
if (object.constructor && object.constructor.name !== 'Object') {
if (object.constructor && object.constructor !== Object) {
// probably an object of an ES6 class
keys = Object.getOwnPropertyNames(Object.getPrototypeOf(object));
} else {
// other object
keys = Object.keys(object);
context.output += `[${object.constructor.name}]`;
}
} catch (err) {
// ES6 proxy objects don't support key enumeration
@ -1141,7 +1139,7 @@ global.DEFINE_MODULE('internal', (function () {
// hide ctor
continue;
}
if (useColor) {
context.output += colors.COLOR_PUNCTUATION;
}
@ -1544,7 +1542,7 @@ global.DEFINE_MODULE('internal', (function () {
limitString: false,
names: [],
output: '',
prettyPrint: true,
prettyPrint: !options || options.prettyPrint !== false,
path: '~',
seen: [],
showFunction: true,
@ -1552,10 +1550,6 @@ global.DEFINE_MODULE('internal', (function () {
useToString: false
};
if (options && options.hasOwnProperty('prettyPrint')) {
context.prettyPrint = options.prettyPrint;
}
printRecursive(object, context);
return context.output;