Kaidul

Untitled

Apr 9th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. public static EventLog parseLog(String logtxt) {
  2.        
  3.         EventLog eventLog = new EventLog();
  4.        
  5.         try {
  6.             Matcher logMatcher = logPattern.matcher(logtxt);
  7.             if (!logMatcher.matches()) {
  8.                 logger.warn("Log text can't be matched with EventLog pattern: " + logtxt);
  9.             }
  10.             int grpCount = logMatcher.groupCount();
  11.            
  12.             if(grpCount >= 1) {
  13.                 eventLog.setTimestamp(logMatcher.group(1));
  14.             }
  15.             if(grpCount >= 2) {
  16.                 eventLog.setLogLevel(logMatcher.group(2));
  17.             }
  18.             if(grpCount >= 3) {
  19.                 eventLog.setEventType(logMatcher.group(3));
  20.             }
  21.             if(grpCount >= 4) {
  22.                 eventLog.setRequestId(logMatcher.group(4));
  23.             }
  24.             if(grpCount >= 6) {
  25.                 eventLog.setMethodName(logMatcher.group(6));
  26.             }
  27.            
  28.             String funcArgs = null;
  29.             if(grpCount >= 7) {
  30.                 funcArgs = logMatcher.group(7);
  31.             }
  32.            
  33.             Map<String, String> args = null;
  34.            
  35.             if (funcArgs != null) {
  36.                 args = new HashMap<>();
  37.                 Matcher keyValueMatcher = keyValuePattern.matcher(funcArgs);
  38.  
  39.                 while (keyValueMatcher.find()) {
  40.                     String key = keyValueMatcher.group(1);
  41.                     String value = keyValueMatcher.group(2);
  42.                     args.put(key, value);
  43.                 }
  44.             }
  45.            
  46.         } catch(Exception ex) {
  47.             logger.error("Error parsing eventLog text: " + logtxt);
  48.             logger.error("Exception: " + ex);
  49.         }
  50.        
  51.         return eventLog;
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment