/
counsell.js
44 lines (36 loc) · 1.14 KB
/
counsell.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
var methods = ["debug", "error", "info", "log", "warn", "dir", "dirxml", "table", "trace", "assert", "count", "markTimeline", "profile", "profileEnd", "time", "timeEnd", "timeStamp", "group", "groupCollapsed", "groupEnd", "clear"],
con = module.exports = {},
i,
len = methods.length,
emptyFn = function() {},
createConsoleFn,
timeIds;
if (typeof console === 'undefined') {
for (i = 0; i < len; ++i) {
con[methods[i]] = emptyFn;
}
} else {
createConsoleFn = function(methodName) {
if (console[methodName]) {
return function() {
return console[methodName].apply(console, arguments);
};
}
return emptyFn;
};
for (i = 0; i < len; ++i) {
con[methods[i]] = createConsoleFn(methods[i]);
}
//IE
if(con.time === emptyFn) {
timeIds = {};
con.time = function(id) {
timeIds[id] = new Date().getTime();
};
con.timeEnd = function(id) {
var millis = new Date().getTime() - timeIds[id];
delete timeIds.id;
console.log('%s: %sms', id, millis);
};
}
}