Hi all i have created aspect for error logging which logs error when any exception is thrown, but i want to save the log in sqllite database android but how to do that in aspect.
Following is my aspect code:
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);
}
}
Aucun commentaire:
Enregistrer un commentaire