的问题是有点误导,因为它意味着需要 将日期解析为java.util.Date
对象或类似物。真正的 的问题是如何将输入数据分割成所需的字段:
This是一个使用正则表达式的解决方案。
String pattern = "^(\\d{2}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})" // date
+ "[ ]+(SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST)" // level
+ "[ ]+([^:]+):(\\d+)" // location name, location line
+ "[ ]+-[ ]+([^:]+): (.*?)" // exception name, exception message
+ "[ ]+Dump: ([a-zA-Z0-9\\./]+)" // dump
+ "$";
Pattern regex = Pattern.compile(pattern);
String input = "09-22-11 12:58:40 SEVERE ...ractBlobAodCommand:104 - IllegalStateException: version:1316719189017 not found in recent history Dump: /data1/aafghani/dev/devamir/logs/dumps/22i125840.dump";
Matcher m = regex.matcher(input);
assertTrue(m.matches());
assertSame(7, m.groupCount());
for (int i = 1; i <= m.groupCount(); i++) {
System.out.format("[%d] \"%s\"%n", i, m.group(i));
}
输出
[1] "09-22-11 12:58:40"
[2] "SEVERE"
[3] "...ractBlobAodCommand"
[4] "104"
[5] "IllegalStateException"
[6] "version:1316719189017 not found in recent history"
[7] "/data1/aafghani/dev/devamir/logs/dumps/22i125840.dump"
来源
2011-10-08 22:01:57
TJR
你想要什么领域?这个例子中的领域应该是什么?数据如何变化? – TJR
嗨TJ - 我想要日期,严重性,类名和行号,异常消息和转储文件。 –