|
@@ -31,19 +31,19 @@ import com.thinkgem.jeesite.modules.sys.entity.User;
|
|
|
* @version 2014-11-7
|
|
|
*/
|
|
|
public class LogUtils {
|
|
|
-
|
|
|
+
|
|
|
public static final String CACHE_MENU_NAME_PATH_MAP = "menuNamePathMap";
|
|
|
-
|
|
|
+
|
|
|
private static LogDao logDao = SpringContextHolder.getBean(LogDao.class);
|
|
|
private static MenuDao menuDao = SpringContextHolder.getBean(MenuDao.class);
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 保存日志
|
|
|
*/
|
|
|
public static void saveLog(HttpServletRequest request, String title){
|
|
|
saveLog(request, null, null, title);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 保存日志
|
|
|
*/
|
|
@@ -67,39 +67,45 @@ public class LogUtils {
|
|
|
* 保存日志线程
|
|
|
*/
|
|
|
public static class SaveLogThread extends Thread{
|
|
|
-
|
|
|
+
|
|
|
private Log log;
|
|
|
private Object handler;
|
|
|
private Exception ex;
|
|
|
-
|
|
|
+
|
|
|
public SaveLogThread(Log log, Object handler, Exception ex){
|
|
|
super(SaveLogThread.class.getSimpleName());
|
|
|
this.log = log;
|
|
|
this.handler = handler;
|
|
|
this.ex = ex;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- // 获取日志标题
|
|
|
- if (StringUtils.isBlank(log.getTitle())){
|
|
|
- String permission = "";
|
|
|
- if (handler instanceof HandlerMethod){
|
|
|
- Method m = ((HandlerMethod)handler).getMethod();
|
|
|
- RequiresPermissions rp = m.getAnnotation(RequiresPermissions.class);
|
|
|
- permission = (rp != null ? StringUtils.join(rp.value(), ",") : "");
|
|
|
+ boolean isPost = StringUtils.equals("POST", log.getMethod());
|
|
|
+ String errString = Exceptions.getStackTraceAsString(ex);
|
|
|
+ if (isPost || StringUtils.isNotBlank(errString)){
|
|
|
+ // POST操作 或 异常日志,保存信息
|
|
|
+ if (StringUtils.isNotBlank(errString)) {
|
|
|
+ // 如果有异常,设置异常信息
|
|
|
+ log.setException(errString);
|
|
|
}
|
|
|
- log.setTitle(getMenuNamePath(log.getRequestUri(), permission));
|
|
|
- }
|
|
|
- // 如果有异常,设置异常信息
|
|
|
- log.setException(Exceptions.getStackTraceAsString(ex));
|
|
|
- // 如果无标题并无异常日志,则不保存信息
|
|
|
- if (StringUtils.isBlank(log.getTitle()) && StringUtils.isBlank(log.getException())){
|
|
|
+ // 获取日志标题
|
|
|
+ if (StringUtils.isBlank(log.getTitle())){
|
|
|
+ String permission = "";
|
|
|
+ if (handler instanceof HandlerMethod){
|
|
|
+ Method m = ((HandlerMethod)handler).getMethod();
|
|
|
+ RequiresPermissions rp = m.getAnnotation(RequiresPermissions.class);
|
|
|
+ permission = (rp != null ? StringUtils.join(rp.value(), ",") : "");
|
|
|
+ }
|
|
|
+ log.setTitle(getMenuNamePath(log.getRequestUri(), permission));
|
|
|
+ }
|
|
|
+ // 保存日志信息
|
|
|
+ log.preInsert();
|
|
|
+ logDao.insert(log);
|
|
|
+ } else {
|
|
|
+ // 如果非POST操作 或 无异常日志,则不保存信息
|
|
|
return;
|
|
|
}
|
|
|
- // 保存日志信息
|
|
|
- log.preInsert();
|
|
|
- logDao.insert(log);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -140,7 +146,7 @@ public class LogUtils {
|
|
|
menuMap.put(p, namePath);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
CacheUtils.put(CACHE_MENU_NAME_PATH_MAP, menuMap);
|
|
|
}
|
|
@@ -159,5 +165,5 @@ public class LogUtils {
|
|
|
return menuNamePath;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|