Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static EventLog parseLog(String logtxt) {
- EventLog eventLog = new EventLog();
- try {
- Matcher logMatcher = logPattern.matcher(logtxt);
- if (!logMatcher.matches()) {
- logger.warn("Log text can't be matched with EventLog pattern: " + logtxt);
- }
- int grpCount = logMatcher.groupCount();
- if(grpCount >= 1) {
- eventLog.setTimestamp(logMatcher.group(1));
- }
- if(grpCount >= 2) {
- eventLog.setLogLevel(logMatcher.group(2));
- }
- if(grpCount >= 3) {
- eventLog.setEventType(logMatcher.group(3));
- }
- if(grpCount >= 4) {
- eventLog.setRequestId(logMatcher.group(4));
- }
- if(grpCount >= 6) {
- eventLog.setMethodName(logMatcher.group(6));
- }
- String funcArgs = null;
- if(grpCount >= 7) {
- funcArgs = logMatcher.group(7);
- }
- Map<String, String> args = null;
- if (funcArgs != null) {
- args = new HashMap<>();
- Matcher keyValueMatcher = keyValuePattern.matcher(funcArgs);
- while (keyValueMatcher.find()) {
- String key = keyValueMatcher.group(1);
- String value = keyValueMatcher.group(2);
- args.put(key, value);
- }
- }
- } catch(Exception ex) {
- logger.error("Error parsing eventLog text: " + logtxt);
- logger.error("Exception: " + ex);
- }
- return eventLog;
- }
Advertisement
Add Comment
Please, Sign In to add comment