-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.js
55 lines (41 loc) · 1.14 KB
/
debug.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
42
43
44
45
46
47
48
49
50
51
52
53
var prettyjson = require('prettyjson')
require('colors')
//logging
var options = {
noColor: false,
keysColor: 'yellow'
}
global.log = function (data, message) {
if (data === undefined || data === null) { data = '[undefined/null]' }
var header = '============================='
if (message) { header = message + ' ' + header }
console.log(header.blue)
try {
console.log(prettyjson.render(data, options))
} catch (err) {
console.log('!!!!!!!!!!!!PRETTYJSON FAILED!!!!!!!!!!!!!!')
t()
// console.log('err: ', err)
// console.log('data: ', data)
}
}
//tracing
global.t = global.t = function () {
var modules = (new Error).stack.split('\n');
var stack = []
for (var i = 2; i < modules.length; i++) {
var x = modules[i].split('(')
x = x[x.length - 1]
x = x.split('/')
x = x[x.length - 1].trim().replace(')', '')
stack.push(x)
if (i > 6) {
break;
}
}
var m = '===> stack trace: ' + stack.join(' | ')
console.log(m.yellow)
if (arguments.length > 0) {
log.apply(this, arguments)
}
}