大家好我已经创建了错误日志记录的方面,当引发任何异常时会记录错误,但是我想将日志保存在sqllite数据库android中,但是如何在方面做到这一点。
以下是我的方面代码:
public aspect ErrorLog {
private long startTime, endTime, elapsedTime;
private Signature sig;
private String line, sourceName;
pointcut publicCalls() : (execution(* *(..))&& !cflow(within(Trace)));
before(): publicCalls(){
startTime = System.currentTimeMillis();
}
after(): publicCalls(){
if (LogConfig.isTraceEnabled) {
sig = thisJoinPointStaticPart.getSignature();
line = "" + thisJoinPointStaticPart.getSourceLocation().getLine();
sourceName = thisJoinPointStaticPart.getSourceLocation()
.getWithinType().getCanonicalName();
endTime = System.currentTimeMillis();
}
}
after() throwing(Throwable e) : publicCalls() {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(endTime);
Logger.getLogger("Error").log(
Level.SEVERE,
"[XPLOGGER]: " + "Time: " + calendar.getTime() + " Class: "
+ sourceName + " Line No.: " + line + " MethodName: "
+ sig.getDeclaringTypeName() + "." + sig.getName()
+ " Exception: " + e);
}
}