update Ox.Log
This commit is contained in:
parent
e2c2eeed43
commit
92d25b6776
1 changed files with 37 additions and 9 deletions
|
@ -123,27 +123,55 @@ Ox.load = function() {
|
||||||
|
|
||||||
Ox.Log = (function() {
|
Ox.Log = (function() {
|
||||||
var filter = localStorage && localStorage.filter
|
var filter = localStorage && localStorage.filter
|
||||||
? JSON.parse(localStorage.filter) : 0,
|
? JSON.parse(localStorage.filter)
|
||||||
|
: {enabled: true, matches: []},
|
||||||
that = function() {
|
that = function() {
|
||||||
return that.log.apply(null, arguments);
|
return that.log.apply(null, arguments);
|
||||||
};
|
};
|
||||||
that.filter = function(value) {
|
function saveFilter() {
|
||||||
filter = value;
|
|
||||||
if (localStorage) {
|
if (localStorage) {
|
||||||
localStorage.filter = JSON.stringify(filter);
|
localStorage.filter = JSON.stringify(filter);
|
||||||
}
|
}
|
||||||
return that;
|
}
|
||||||
|
that.filter = function(val) {
|
||||||
|
var ret;
|
||||||
|
if (Ox.isUndefined(val)) {
|
||||||
|
ret = filter.matches;
|
||||||
|
} else {
|
||||||
|
filter.matches = Ox.toArray(val);
|
||||||
|
saveFilter();
|
||||||
|
ret = that;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
that.filter.add = function(val) {
|
||||||
|
return that.filter(Ox.unique(Ox.merge(filter, Ox.toArray(val))));
|
||||||
|
};
|
||||||
|
that.filter.disable = function() {
|
||||||
|
filter.enabled = false;
|
||||||
|
saveFilter();
|
||||||
|
};
|
||||||
|
that.filter.enable = function() {
|
||||||
|
filter.enabled = true;
|
||||||
|
saveFilter();
|
||||||
|
};
|
||||||
|
that.filter.remove = function(val) {
|
||||||
|
val = Ox.toArray(val);
|
||||||
|
return that.filter(filter.matches.filter(function(v) {
|
||||||
|
return val.indexOf(v) == -1;
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
that.log = function log() {
|
that.log = function log() {
|
||||||
var args = Ox.makeArray(arguments),
|
var args = Ox.makeArray(arguments), date, ret;
|
||||||
level = Ox.isNumber(args[0]) ? args[0] : 0,
|
if (!filter.enabled || filter.matches.indexOf(args[0]) > -1) {
|
||||||
ret;
|
date = new Date();
|
||||||
if ((Ox.isNumber(filter) && level >= filter) || filter === args[0]) {
|
|
||||||
args.unshift(
|
args.unshift(
|
||||||
|
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3),
|
||||||
(arguments.callee.caller && arguments.callee.caller.name)
|
(arguments.callee.caller && arguments.callee.caller.name)
|
||||||
|| '(anonymous)'
|
|| '(anonymous)'
|
||||||
);
|
);
|
||||||
ret = Ox.print.apply(null, args);
|
window.console && window.console.log.apply(window.console, args);
|
||||||
|
ret = args.join(' ');
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue