forked from HenrikJoreteg/andlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
andlog.js
39 lines (35 loc) · 1.07 KB
/
andlog.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
// follow @HenrikJoreteg and @andyet if you like this ;)
(function () {
function getLocalStorageSafely() {
var localStorage;
try {
localStorage = window.localStorage;
} catch (e) {
// failed: access to localStorage is denied
}
return localStorage;
}
var inNode = typeof window === 'undefined',
ls = !inNode && getLocalStorageSafely(),
out = {};
if (inNode) {
module.exports = console;
return;
}
var andlogKey = ls.andlogKey || 'debug'
if (ls && ls[andlogKey] && window.console) {
out = window.console;
} else {
var methods = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),
l = methods.length,
fn = function () {};
while (l--) {
out[methods[l]] = fn;
}
}
if (typeof exports !== 'undefined') {
module.exports = out;
} else {
window.console = out;
}
})();