目前遇到的用法基本上是这样的,@SLog(tag = "Add", msg = "Add:sOrder")
如果想要使用它纪录异常,目前wk(并非最新的slog)该怎么改呢?
@At("/test")
@SLog(tag = "test", msg = "${obj.msg}")
public Object test(HttpServletRequest req) {
try {
throw new RuntimeException("456");
} catch (Exception e) {
return Result.error("test-error");
}
}
result构造
public Result(int code, String msg, Object data) {
this.code = code;
this.msg = Mvcs.getMessage(Mvcs.getActionContext().getRequest(), msg);
this.data = data;
}
本来想用 msg = "${obj.xxx}"
看了帖子发现obj好像是被注解的方法所在的类。
目前SysLogAopInterceptor的方法
public SysLogAopInterceptor(SysLogService sysLogService, SLog slog, Method method) {
this.msg = new CharSegment(slog.msg());
if (msg.hasKey()) {
els = new HashMap<String, El>();
for (String key : msg.keys()) {
els.put(key, new El(key));
}
}
this.sysLogService = sysLogService;
this.source = method.getDeclaringClass().getName() + "#" + method.getName();
this.tag = slog.tag();
SLog _s = method.getDeclaringClass().getAnnotation(SLog.class);
if (_s != null) {
this.tag = _s.tag() + "," + this.tag;
}
this.async = slog.async();
this.before = slog.before();
this.after = slog.after();
this.error = slog.error();
}
public void filter(InterceptorChain chain) throws Throwable {
if (before)
doLog("aop.before", chain, null);
try {
chain.doChain();
if (after)
doLog("aop.after", chain, null);
} catch (Throwable e) {
if (error)
doLog("aop.after", chain, e);
throw e;
}
}
protected void doLog(String t, InterceptorChain chain, Throwable e) {
String _msg = null;
if (msg.hasKey()) {
Context ctx = Lang.context();
ctx.set("args", chain.getArgs());
ctx.set("return", chain.getReturn());
Context _ctx = Lang.context();
for (String key : msg.keys()) {
_ctx.set(key, els.get(key).eval(ctx));
}
_msg = msg.render(_ctx).toString();
} else {
_msg = msg.getOrginalString();
}
Sys_log sysLog = Sys_log.c(t, tag, _msg, source);
if (async)
sysLogService.async(sysLog);
else
sysLogService.sync(sysLog);
}
最新版的slog代码还在看,感觉要换的话要动很多东西囧