diff --git a/source/Ox/js/Core.js b/source/Ox/js/Core.js index 5b0e7a4a..804650a1 100644 --- a/source/Ox/js/Core.js +++ b/source/Ox/js/Core.js @@ -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; };