mirror of
https://github.com/mathew-kurian/Scribe.js
synced 2025-09-14 12:41:11 +00:00
Pretty log for objects
This commit is contained in:
parent
7f65af38a7
commit
83243b9718
1 changed files with 34 additions and 1 deletions
|
@ -309,8 +309,41 @@
|
|||
result += new Array(offset + this.opt.spaceSize).join(' ');
|
||||
}
|
||||
|
||||
result += log.argsString;
|
||||
//It's time to log the args
|
||||
|
||||
var args = Array.prototype.slice.call(log.args, 0), //transform args in an array
|
||||
msg = "", //the log message
|
||||
delimiter = '\n\n',
|
||||
multiLines = false; //if the log need multiples lines (ie. object, array)
|
||||
|
||||
//Process arg one by one
|
||||
args.forEach(function (arg) {
|
||||
|
||||
//if arg is an object / array
|
||||
//use multiples lines
|
||||
if (arg !== null && typeof arg === 'object') {
|
||||
|
||||
msg += delimiter;
|
||||
|
||||
msg += JSON.stringify(arg, null, 2);
|
||||
|
||||
multiLines = true;
|
||||
|
||||
//for "normal" args
|
||||
} else {
|
||||
if (multiLines) {
|
||||
msg += delimiter;
|
||||
}
|
||||
msg += arg + "";
|
||||
}
|
||||
});
|
||||
|
||||
if (multiLines) {
|
||||
msg += '\n';
|
||||
msg = msg.replace(/\n/gm, '\n' + new Array(this.opt.spaceSize).join(' '));
|
||||
}
|
||||
|
||||
result += msg;
|
||||
|
||||
return result;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue