forked from patik/console.log-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsolelog.js
More file actions
53 lines (49 loc) · 2.27 KB
/
Copy pathconsolelog.js
File metadata and controls
53 lines (49 loc) · 2.27 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
// Tell IE9 to use its built-in console
if (Function.prototype.bind && (typeof console === 'object' || typeof console === 'function') && typeof console.log === "object") {
["log","info","warn","error","assert","dir","clear","profile","profileEnd"]
.forEach(function (method) {
console[method] = this.call(console[method], console);
}, Function.prototype.bind);
}
// log() -- The complete, cross-browser (we don't judge!) console.log wrapper for his or her logging pleasure
if (!window.log) {
window.log = function () {
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
// Modern browsers
if (typeof console != 'undefined' && typeof console.log == 'function') {
// Single argument, which is a string
if ((Array.prototype.slice.call(arguments)).length === 1 && typeof Array.prototype.slice.call(arguments)[0] === 'string') {
console.log( (Array.prototype.slice.call(arguments)).toString() );
}
else {
console.log( Array.prototype.slice.call(arguments) );
}
}
// IE8
else if (!Function.prototype.bind && typeof console !== 'undefined' && typeof console.log === 'object') {
Function.prototype.call.call(console.log, console, Array.prototype.slice.call(arguments));
}
// IE7 and lower, and other old browsers
else {
var args = arguments;
// Inject Firebug lite
if (!document.getElementById('firebug-lite')) {
// Include the script
var script = document.createElement('script');
script.type = "text/javascript";
script.id = 'firebug-lite';
// If you run the script locally, point to /path/to/firebug-lite/build/firebug-lite.js
script.src = 'https://getfirebug.com/firebug-lite.js';
// If you want to expand the console window by default, uncomment this line
//document.getElementsByTagName('HTML')[0].setAttribute('debug','true');
document.getElementsByTagName('HEAD')[0].appendChild(script);
setTimeout(function () { window.log.apply(window, args); }, 2000);
}
else {
// FBL was included but it hasn't finished loading yet, so try again momentarily
setTimeout(function () { window.log.apply(window, args); }, 500);
}
}
};
}