update Ox.Log

This commit is contained in:
rlx 2011-11-04 16:34:24 +00:00
parent 9422780d65
commit d6cbc594bc

View file

@ -124,11 +124,11 @@ Ox.load = function() {
Ox.Log = (function() {
var log = localStorage && localStorage.OxLog
? JSON.parse(localStorage.OxLog)
: {enabled: false, filter: []},
: {filter: [], filterEnabled: true},
that = function() {
var ret;
if (arguments.length == 0) {
ret = log.enabled;
ret = log;
} else {
ret = that.log.apply(null, arguments);
}
@ -139,37 +139,33 @@ Ox.Log = (function() {
localStorage.OxLog = JSON.stringify(log);
}
}
that.disable = function() {
log.enabled = false;
save();
};
that.enable = function() {
log.enabled = true;
save();
};
that.filter = function(val) {
var ret;
if (Ox.isUndefined(val)) {
ret = log.filter;
} else {
if (!Ox.isUndefined(val)) {
log.filter = Ox.toArray(val);
save();
ret = that;
}
return ret;
return log.filter;
};
that.filter.add = function(val) {
return that.filter(Ox.unique(Ox.merge(log.filter, Ox.toArray(val))));
};
that.filter.disable = function() {
log.filterEnabled = false;
save();
};
that.filter.enable = function() {
log.filterEnabled = true;
save();
};
that.filter.remove = function(val) {
val = Ox.toArray(val);
return that.filter(log.filter.filter(function(v) {
return val.indexOf(v) == -1;
}));
};
that.log = function log() {
that.log = function() {
var args = Ox.makeArray(arguments), date, ret;
if (log.enabled && log.filter.indexOf(args[0]) > -1) {
if (!log.filterEnabled || log.filter.indexOf(args[0]) > -1) {
date = new Date();
args.unshift(
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3),