-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.js
executable file
·41 lines (38 loc) · 924 Bytes
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require('console.table');
var _ = require('lodash');
function useTable(obj) {
if(!Array.isArray(obj) || obj.length == 1) {
return false;
}
var k0 = _.keys(obj[0]);
if(k0.length > 15) {
return false;
}
if(k0.join() != _.keys(obj[1]).join()) {
return false;
}
return true;
}
module.exports = function(obj, obj2) {
if(obj2) {
console.log('\n===' + obj2 + '===');
}
try {
if(typeof obj == 'object') {
if(useTable(obj)) {
console.table(obj);
} else {
var jso = JSON.stringify(obj);
if(jso.length > 100) {
console.log(JSON.stringify(obj, 0, ' '));
} else {
console.log(jso);
}
}
} else {
console.log(obj);
}
} catch(e) {
console.log(obj);
}
}