-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.js
61 lines (55 loc) · 1.3 KB
/
console.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
54
55
56
57
58
59
60
61
/* UMD.define */ (typeof define=="function"&&define||function(d,f,m){m={module:module,require:require};module.exports=f.apply(null,d.map(function(n){return m[n]||require(n)}))})
(["./main"], function(ice){
"use strict";
function format(args){
var result = "", msg = args[0], i = 0;
if(typeof msg == "string"){
result = msg.replace(/%[difsj]/g, function(pattern){
if(pattern == "%s"){
return "" + args[++i];
}
if(pattern == "%j"){
return JSON.stringify(args[++i]);
}
return "" + (+args[++i]);
});
}
var rest = [];
for(++i; i < args.length; ++i){
rest.push("" + args[i]);
}
if(!rest.length){
return result;
}
if(result){
return result + " " + rest.join(" ");
}
return rest.join(" ");
}
function log(name){
return function(){
var args = Array.prototype.slice.call(arguments, 0);
this.ice[name](format(args), args);
};
}
function Console(specialIce){
this.ice = specialIce || ice;
}
var cp = Console.prototype = {
log: log("info"),
info: log("info"),
warn: log("warn"),
error: log("error"),
specialize: function(specialIce){
return new Console(specialIce);
}
};
if(typeof console == "object"){
for(var name in console){
if(!cp.hasOwnProperty(name)){
cp[name] = console[name];
}
}
}
return new Console();
});