json - parsing log file using java Grok api not working but working in Grok online debugger (solved) -


hi have problem when parsing log file using code , grok api downloaded github (i'm not using logstash) when test using grok debugger https://grokdebug.herokuapp.com/ works fine in code won't

here log line file want parse :

debug 2015-06-17 14:44:57,475 (com.test.logging.exceptionmanager.exceptiontreemodel:findnodebyidrecursively:651) - not find node id: 1913

and code :

public class logparse {     public static void main(string[] args) throws grokexception, ioexception {           // instance of grok         grok grok = new grok();          // add pattern grok         grok.addpattern("loglevel", "\\w+");         grok.addpattern("year", "\\w+");         grok.addpattern("monthnum", "((?:0?[1-9]|1[0-2]))");         grok.addpattern("monthday", "(?:[+-]?(?:[0-9]+))");         grok.addpattern("hour", "(?:[+-]?(?:[0-9]+))");         grok.addpattern("minute", "(?:[+-]?(?:[0-9]+))");         grok.addpattern("second", "(?:(?:[0-5][0-9]|60)(?:[:.,][0-9]+)?)");         grok.addpattern("greedydata", ".*");           grok.compile("%{loglevel:loglevel} %{year:year}-%{monthnum:month}-%{monthday:day} %{hour:hour}:%{minute:minute}:%{second:second} (%{greedydata:data}) - %{greedydata:message} %{greedydata:erreur}");         grok.compile("%{loglevel:loglevel} %{year:year}-%{monthnum:month}-%{monthday:day} %{hour:hour}:%{minute:minute}:%{second:second} (%{greedydata:data}) - %{greedydata:message}");           try{                 fileinputstream fstream = new fileinputstream("c://file.log");                bufferedreader br = new bufferedreader(new inputstreamreader(fstream));                string log;                 //output                 bufferedwriter output = new bufferedwriter(new filewriter("out.json"));                 /* read log line line */                while ((log = br.readline()) != null)   {                   system.out.println (log);                  match gm = grok.match(log);                     gm.captures();                      //output                     system.out.println(gm.tojson());                     output.write(gm.tojson());                     output.newline();                 }                output.close();                fstream.close();              } catch (exception e) {                  system.err.println("error: " + e.getmessage());             }   }} 

thanks help.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -