1
我们都在收集大量的日志中,我们将使用一个数据库或文件来存储这些日志,并希望能够通过文本搜索通过它们进行搜索。有没有办法有效地做到这一点。Hibernate Search的记录文本文件
我们都在收集大量的日志中,我们将使用一个数据库或文件来存储这些日志,并希望能够通过文本搜索通过它们进行搜索。有没有办法有效地做到这一点。Hibernate Search的记录文本文件
所以,你要做的就是
ExceptionPersistingService eps = new ExceptionPersistingService();
try{
//some code that might trow exception
}catch(Exception e){
eps.saveNewExceptin(getStackTrace(e));
}
public static String getStackTrace(Throwable aThrowable) {
//add the class name and any message passed to constructor
final StringBuilder result = new StringBuilder("Trace: ");
result.append(aThrowable.toString());
final String NEW_LINE = "<br>";
result.append(NEW_LINE);
//add each element of the stack trace
for (StackTraceElement element : aThrowable.getStackTrace()) {
result.append(element);
result.append(NEW_LINE);
}
return result.toString();
}
比你创建Lucene的实施(我推荐使用Hibernate Search的),将索引你存储在数据库中的异常字符串。在save()方法中,您可以创建对象PersistentException,该对象具有ID
,Date
,ExceptionString
,User
,甚至可能是URL
发生异常的详细信息。
比所有你所要做的就是分析你的查询,创建模糊或其他任何的查询和享受的搜索结果。欲了解更多详情,你将不得不研究书籍,如Hibernate Search in Action
和Lucene in Action
。他们有很好的例子来说明我刚才简单提到的做法。