-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug.js
More file actions
144 lines (121 loc) · 2.98 KB
/
debug.js
File metadata and controls
144 lines (121 loc) · 2.98 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
window.debug = (function() {
var level = 9;
var ignoring = [];
var highlighting = [];
var colours = [];
function doTheLogging(css, module, logtype, args) {
var string = module;
if (ignoring[module]) {
css = "color:#cccccc";
} else if (highlighting[module]) {
css = "font-weight:bold";
}
while (string.length < 18) {
string = string + " ";
}
string = string + ": ";
for (var i in args) {
if (typeof(args[i]) != "object" || args[i] === null || args[i] === undefined) {
string = string + " " + args[i];
}
}
if (css != "") {
console[logtype]("%c"+string,css);
} else {
console[logtype](string);
}
for (var i in args) {
if (typeof(args[i]) == "object" && args[i] !== null && args[i] !== undefined) {
if (ignoring[module]) {
console.log(" %O",args[i]);
} else {
console.log(" ",args[i]);
}
}
}
}
return {
setLevel: function(l) {
level = l;
},
// Level 9
debug: function() {
if (level > 8) {
var args = Array.prototype.slice.call(arguments);
var module = args.shift();
doTheLogging("color:#999999", module, 'log', args);
}
},
// Level 8
log: function() {
if (level > 7) {
var args = Array.prototype.slice.call(arguments);
var module = args.shift();
doTheLogging("", module, 'log', args);
}
},
// Level 7
mark: function() {
if (level > 6) {
var args = Array.prototype.slice.call(arguments);
var module = args.shift();
var colour = '#22fe00';
if (colours[module]) { colour = colours[module] }
doTheLogging("color:"+colour, module, 'log', args);
}
},
// Level 3
fail: function() {
if (level > 2) {
var args = Array.prototype.slice.call(arguments);
var module = args.shift();
doTheLogging("color:#ff0000", module, 'log', args);
}
},
// Level 2
warn: function() {
if (level > 1) {
var args = Array.prototype.slice.call(arguments);
var module = args.shift();
doTheLogging("", module, 'warn', args);
}
},
// Groups operate at level 2
group: function() {
if (level > 1) {
var args = Array.prototype.slice.call(arguments);
var module = args.shift();
if (ignoring[module]) {
doTheLogging("", module, 'groupCollapsed', args);
} else {
doTheLogging("", module, 'group', args);
}
}
},
groupend: function() {
if (level > 1) {
console.groupEnd();
}
},
// Level 1
error: function() {
if (level > 0) {
var args = Array.prototype.slice.call(arguments);
var module = args.shift();
doTheLogging("", module, 'error', args);
}
},
ignore: function(module) {
ignoring[module] = true;
},
highlight: function(module) {
highlighting[module] = true;
},
// Use this to set the colour used in debug.mark for a specific module
// Otherwise, a lurid green will be used :)
// Specify your colour as a string, like #fe6830
setcolour: function(module, colour) {
colours[module] = colour;
}
}
})();