title: parsing log4j log file using regular expression
body: <p>I have created a java application for parsing the log4j log file using regular expression, The application is working fine for the log which i have shown below</p>
  
  <pre><code>1999-11-27 15:49:37,459 [thread-x] ERROR mypackage - Catastrophic system failure
  </code></pre>
  
  <p>but not working for </p>
  
  <pre><code>2015-01-22 01:52:54,237 [http-bio-80-exec-5] FATAL   TestLog4jServlet - Show FATAL message
  </code></pre>
  
  <p>My log4j ConversionPattern is given below</p>
  
  <pre><code>log4j.appender.Appender2.layout.ConversionPattern=%d [%t] %-7p %10c{1} - %m%n
  </code></pre>
  
  <p>Can anyone please tell me some solution for this</p>
  
  <p>My code is as given below</p>
  
  <pre><code>public static void main(String[] args) {
      String regex = "(\\d{4}-\\d{2}-\\d{2}) (\\d{2}:\\d{2}:\\d{2},\\d{3}) \\[(.*)\\] ([^ ]*) ([^ ]*) - (.*)$";
  
      Pattern p = Pattern.compile(regex);
      String[] samples = {
              "2015-01-22 01:52:54,237 [http-bio-80-exec-5] FATAL   TestLog4jServlet - Show FATAL message"
          };
  
      Matcher m = p.matcher(samples[1]);
      System.out.println(m.matches());
      if (m.matches() &amp;&amp; m.groupCount() == 6) {
          String date = m.group(1);
          String time = m.group(2);
          String threadId = m.group(3);
          String priority = m.group(4);
          String category = m.group(5);
          String message = m.group(6);
  
          System.out.println("date: " + date);
          System.out.println("time: " + time);
          System.out.println("threadId: " + threadId);
          System.out.println("priority: " + priority);
          System.out.println("category: " + category);
          System.out.println("message: " + message);
      }
  }
  </code></pre>