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() {
|
||||
var filter = localStorage && localStorage.filter
|
||||
? JSON.parse(localStorage.filter) : 0,
|
||||
? JSON.parse(localStorage.filter)
|
||||
: {enabled: true, matches: []},
|
||||
that = function() {
|
||||
return that.log.apply(null, arguments);
|
||||
};
|
||||
that.filter = function(value) {
|
||||
filter = value;
|
||||
function saveFilter() {
|
||||
if (localStorage) {
|
||||
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() {
|
||||
var args = Ox.makeArray(arguments),
|
||||
level = Ox.isNumber(args[0]) ? args[0] : 0,
|
||||
ret;
|
||||
if ((Ox.isNumber(filter) && level >= filter) || filter === args[0]) {
|
||||
var args = Ox.makeArray(arguments), date, ret;
|
||||
if (!filter.enabled || filter.matches.indexOf(args[0]) > -1) {
|
||||
date = new Date();
|
||||
args.unshift(
|
||||
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3),
|
||||
(arguments.callee.caller && arguments.callee.caller.name)
|
||||
|| '(anonymous)'
|
||||
);
|
||||
ret = Ox.print.apply(null, args);
|
||||
window.console && window.console.log.apply(window.console, args);
|
||||
ret = args.join(' ');
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue