如何使用aspectj通过方面保存数据库中的android日志

时间:2015-05-20 12:44:56

标签: android sqlite aop aspectj

大家好我已经创建了错误日志记录的方面,当引发任何异常时会记录错误,但是我想将日志保存在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);
    }

}

0 个答案:

没有答案