update Ox.Log
This commit is contained in:
parent
9422780d65
commit
d6cbc594bc
1 changed files with 14 additions and 18 deletions
|
@ -124,11 +124,11 @@ Ox.load = function() {
|
||||||
Ox.Log = (function() {
|
Ox.Log = (function() {
|
||||||
var log = localStorage && localStorage.OxLog
|
var log = localStorage && localStorage.OxLog
|
||||||
? JSON.parse(localStorage.OxLog)
|
? JSON.parse(localStorage.OxLog)
|
||||||
: {enabled: false, filter: []},
|
: {filter: [], filterEnabled: true},
|
||||||
that = function() {
|
that = function() {
|
||||||
var ret;
|
var ret;
|
||||||
if (arguments.length == 0) {
|
if (arguments.length == 0) {
|
||||||
ret = log.enabled;
|
ret = log;
|
||||||
} else {
|
} else {
|
||||||
ret = that.log.apply(null, arguments);
|
ret = that.log.apply(null, arguments);
|
||||||
}
|
}
|
||||||
|
@ -139,37 +139,33 @@ Ox.Log = (function() {
|
||||||
localStorage.OxLog = JSON.stringify(log);
|
localStorage.OxLog = JSON.stringify(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
that.disable = function() {
|
|
||||||
log.enabled = false;
|
|
||||||
save();
|
|
||||||
};
|
|
||||||
that.enable = function() {
|
|
||||||
log.enabled = true;
|
|
||||||
save();
|
|
||||||
};
|
|
||||||
that.filter = function(val) {
|
that.filter = function(val) {
|
||||||
var ret;
|
if (!Ox.isUndefined(val)) {
|
||||||
if (Ox.isUndefined(val)) {
|
|
||||||
ret = log.filter;
|
|
||||||
} else {
|
|
||||||
log.filter = Ox.toArray(val);
|
log.filter = Ox.toArray(val);
|
||||||
save();
|
save();
|
||||||
ret = that;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return log.filter;
|
||||||
};
|
};
|
||||||
that.filter.add = function(val) {
|
that.filter.add = function(val) {
|
||||||
return that.filter(Ox.unique(Ox.merge(log.filter, Ox.toArray(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) {
|
that.filter.remove = function(val) {
|
||||||
val = Ox.toArray(val);
|
val = Ox.toArray(val);
|
||||||
return that.filter(log.filter.filter(function(v) {
|
return that.filter(log.filter.filter(function(v) {
|
||||||
return val.indexOf(v) == -1;
|
return val.indexOf(v) == -1;
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
that.log = function log() {
|
that.log = function() {
|
||||||
var args = Ox.makeArray(arguments), date, ret;
|
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();
|
date = new Date();
|
||||||
args.unshift(
|
args.unshift(
|
||||||
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3),
|
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3),
|
||||||
|
|
Loading…
Reference in a new issue