@Test public void test_メッセージなし() throws ParseException { String logText = StringUtils.join(new String[] { "log.generating.time=Sun Nov 13 15:55:39 KST 2011", "log.level=ERROR", "log.logger.name=jp.co.intra_mart.system.javascript.imapi.ResinDataSourceConfiguraterObject", "log.id=5i0slu795nope", "log.thread.id=http-APP:localhost:8088-8088-0$312771783", "log.thread.group=main", "log.message=", "", "jp.co.intra_mart.foundation.database.exception.DataSourceConfigurationException: ", "\tat jp.co.intra_mart.foundation.database.ResinDataSourceConfigurater.bind(ResinDataSourceConfigurater.java:111)", "\tat jp.co.intra_mart.system.javascript.imapi.ResinDataSourceConfiguraterObject.jsFunction_bind(ResinDataSourceConfiguraterObject.java:152)" }, IOUtils.LINE_SEPARATOR); ExceptionLogParser exceptionLogParser = new ExceptionLogParserV7(new ParserParameter()); ExceptionLog log = exceptionLogParser.parse(logText); assertEquals( new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH).parse("Sun Nov 13 15:55:39 KST 2011"), log.date); assertEquals(Level.ERROR, log.level); assertEquals("jp.co.intra_mart.system.javascript.imapi.ResinDataSourceConfiguraterObject", log.logger); assertEquals("5i0slu795nope", log.logId); assertEquals("http-APP:localhost:8088-8088-0$312771783", log.thread); assertEquals("main", log.logThreadGroup); assertEquals("", log.message); assertEquals("jp.co.intra_mart.foundation.database.exception.DataSourceConfigurationException: ", log.getFirstLineOfStackTrace()); }
public ExceptionLog parse(String string) { if (string == null) { return null; } String[] lines = LogStringUtil.lines(string); if (lines.length < 9) { warn("invalid exception log"); this.parameter.getErrorCounter().increment(); return null; } ExceptionLog log = new ExceptionLog(); log.groupingType = this.parameter.getExceptionGroupingType(); try { log.date = dateFormat.parse(getValue(lines[0])); } catch (ParseException e) { warn("invalid date : " + lines[0]); this.parameter.getErrorCounter().increment(); return null; } if (!isInRange(log)) { return null; } log.level = Level.toEnum(getValue(lines[1])); log.logger = getValue(lines[2]); log.logId = getValue(lines[3]); log.thread = getValue(lines[4]); log.logThreadGroup = getValue(lines[5]); log.message = getValue(lines[6]); for (int i = 7; i < lines.length; i++) { if (lines[i].length() == 0 && i < lines.length - 1 && STACKTRACE_BIGIN_PATTERN.matcher(lines[i + 1]).find()) { log.stackTrace = StringUtils.join( ArrayUtils.subarray(lines, i + 1, lines.length - 1), IOUtils.LINE_SEPARATOR); break; } else { log.message += IOUtils.LINE_SEPARATOR + lines[i]; } } return log; }
ExceptionLogParserV7 extends ExceptionLogParser { public ExceptionLog parse(String string) { if (string == null) { return null; } String[] lines = LogStringUtil.lines(string); if (lines.length < 9) { warn("invalid exception log"); this.parameter.getErrorCounter().increment(); return null; } ExceptionLog log = new ExceptionLog(); log.groupingType = this.parameter.getExceptionGroupingType(); try { log.date = dateFormat.parse(getValue(lines[0])); } catch (ParseException e) { warn("invalid date : " + lines[0]); this.parameter.getErrorCounter().increment(); return null; } if (!isInRange(log)) { return null; } log.level = Level.toEnum(getValue(lines[1])); log.logger = getValue(lines[2]); log.logId = getValue(lines[3]); log.thread = getValue(lines[4]); log.logThreadGroup = getValue(lines[5]); log.message = getValue(lines[6]); for (int i = 7; i < lines.length; i++) { if (lines[i].length() == 0 && i < lines.length - 1 && STACKTRACE_BIGIN_PATTERN.matcher(lines[i + 1]).find()) { log.stackTrace = StringUtils.join( ArrayUtils.subarray(lines, i + 1, lines.length - 1), IOUtils.LINE_SEPARATOR); break; } else { log.message += IOUtils.LINE_SEPARATOR + lines[i]; } } return log; } }
ExceptionLogParserV7 extends ExceptionLogParser { public ExceptionLog parse(String string) { if (string == null) { return null; } String[] lines = LogStringUtil.lines(string); if (lines.length < 9) { warn("invalid exception log"); this.parameter.getErrorCounter().increment(); return null; } ExceptionLog log = new ExceptionLog(); log.groupingType = this.parameter.getExceptionGroupingType(); try { log.date = dateFormat.parse(getValue(lines[0])); } catch (ParseException e) { warn("invalid date : " + lines[0]); this.parameter.getErrorCounter().increment(); return null; } if (!isInRange(log)) { return null; } log.level = Level.toEnum(getValue(lines[1])); log.logger = getValue(lines[2]); log.logId = getValue(lines[3]); log.thread = getValue(lines[4]); log.logThreadGroup = getValue(lines[5]); log.message = getValue(lines[6]); for (int i = 7; i < lines.length; i++) { if (lines[i].length() == 0 && i < lines.length - 1 && STACKTRACE_BIGIN_PATTERN.matcher(lines[i + 1]).find()) { log.stackTrace = StringUtils.join( ArrayUtils.subarray(lines, i + 1, lines.length - 1), IOUtils.LINE_SEPARATOR); break; } else { log.message += IOUtils.LINE_SEPARATOR + lines[i]; } } return log; } ExceptionLogParserV7(ParserParameter parameter); }
ExceptionLogParserV7 extends ExceptionLogParser { public ExceptionLog parse(String string) { if (string == null) { return null; } String[] lines = LogStringUtil.lines(string); if (lines.length < 9) { warn("invalid exception log"); this.parameter.getErrorCounter().increment(); return null; } ExceptionLog log = new ExceptionLog(); log.groupingType = this.parameter.getExceptionGroupingType(); try { log.date = dateFormat.parse(getValue(lines[0])); } catch (ParseException e) { warn("invalid date : " + lines[0]); this.parameter.getErrorCounter().increment(); return null; } if (!isInRange(log)) { return null; } log.level = Level.toEnum(getValue(lines[1])); log.logger = getValue(lines[2]); log.logId = getValue(lines[3]); log.thread = getValue(lines[4]); log.logThreadGroup = getValue(lines[5]); log.message = getValue(lines[6]); for (int i = 7; i < lines.length; i++) { if (lines[i].length() == 0 && i < lines.length - 1 && STACKTRACE_BIGIN_PATTERN.matcher(lines[i + 1]).find()) { log.stackTrace = StringUtils.join( ArrayUtils.subarray(lines, i + 1, lines.length - 1), IOUtils.LINE_SEPARATOR); break; } else { log.message += IOUtils.LINE_SEPARATOR + lines[i]; } } return log; } ExceptionLogParserV7(ParserParameter parameter); ExceptionLog parse(String string); }
ExceptionLogParserV7 extends ExceptionLogParser { public ExceptionLog parse(String string) { if (string == null) { return null; } String[] lines = LogStringUtil.lines(string); if (lines.length < 9) { warn("invalid exception log"); this.parameter.getErrorCounter().increment(); return null; } ExceptionLog log = new ExceptionLog(); log.groupingType = this.parameter.getExceptionGroupingType(); try { log.date = dateFormat.parse(getValue(lines[0])); } catch (ParseException e) { warn("invalid date : " + lines[0]); this.parameter.getErrorCounter().increment(); return null; } if (!isInRange(log)) { return null; } log.level = Level.toEnum(getValue(lines[1])); log.logger = getValue(lines[2]); log.logId = getValue(lines[3]); log.thread = getValue(lines[4]); log.logThreadGroup = getValue(lines[5]); log.message = getValue(lines[6]); for (int i = 7; i < lines.length; i++) { if (lines[i].length() == 0 && i < lines.length - 1 && STACKTRACE_BIGIN_PATTERN.matcher(lines[i + 1]).find()) { log.stackTrace = StringUtils.join( ArrayUtils.subarray(lines, i + 1, lines.length - 1), IOUtils.LINE_SEPARATOR); break; } else { log.message += IOUtils.LINE_SEPARATOR + lines[i]; } } return log; } ExceptionLogParserV7(ParserParameter parameter); ExceptionLog parse(String string);  }