loganalyzer
Version:
A simple log analyzer supporting multiple filters and UI.
6 lines (5 loc) • 2.16 kB
JavaScript
var $jscomp={scope:{},getGlobal:function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global?global:b}};$jscomp.global=$jscomp.getGlobal(this);$jscomp.patches={};$jscomp.patch=function(b,e){($jscomp.patches[b]=$jscomp.patches[b]||[]).push(e);for(var d=$jscomp.global,c=b.split("."),f=0;f<c.length-1&&d;f++)d=d[c[f]];c=c[c.length-1];d&&d[c]instanceof Function&&(d[c]=e(d[c]))};$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};if(!$jscomp.global.Symbol){$jscomp.global.Symbol=$jscomp.Symbol;var b=[],e=function(d){return function(c){b=[];c=d(c);for(var e=[],h=0,l=c.length;h<l;h++){var g;a:if(g=c[h],g.length<$jscomp.SYMBOL_PREFIX.length)g=!1;else{for(var k=0;k<$jscomp.SYMBOL_PREFIX.length;k++)if(g[k]!=$jscomp.SYMBOL_PREFIX[k]){g=!1;break a}g=!0}g?b.push(c[h]):e.push(c[h])}return e}};$jscomp.patch("Object.keys",e);$jscomp.patch("Object.getOwnPropertyNames",e);$jscomp.patch("Object.getOwnPropertySymbols",
function(d){return function(c){e.unused=Object.getOwnPropertyNames(c);b.push.apply(d(c));return b}})}};$jscomp.symbolCounter_=0;$jscomp.Symbol=function(b){return $jscomp.SYMBOL_PREFIX+b+$jscomp.symbolCounter_++};$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();$jscomp.global.Symbol.iterator||($jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));$jscomp.initSymbolIterator=function(){}};
$jscomp.makeIterator=function(b){$jscomp.initSymbolIterator();var e=b[Symbol.iterator];if(e)return e.call(b);var d=0;return{next:function(){return d<b.length?{done:!1,value:b[d++]}:{done:!0}}}};LogAnalyzer=function(b){this.debug_=b.debug;this.filters_=b.filters};
LogAnalyzer.prototype.analyze=function(b,e){for(var d=b.split("\n"),d=$jscomp.makeIterator(d),c=d.next();!c.done;c=d.next()){line=c.value;for(var c=$jscomp.makeIterator(this.filters_),f=c.next();!f.done;f=c.next())filter=f.value,line.match(new RegExp(filter.pattern,"i"))&&e(line)}};LogAnalyzer.ALL_FILTER_={pattern:"",description:"Filter that catches everything"};var a=new LogAnalyzer({debug:!0,filters:[{pattern:"Error"}]});a.analyze("0:00 Start\n0:05 Error\n0:10 End",function(b){console.log(b)});