请问一下,jfinal有没有操作日志的框架,实现目标:
直接自动捕获每一个action,自动存到到日志中。
现在我能实现,但是感觉很不科学,移植性也很差。
请问有类似的模块?类似的项目参考吗?
我现在的做法:
每个方法写:
CommonService.me.log(this, "xxx", "xxx", context);
// 导出单月公司统计表 : 公司、年、月 public void getStatisticalTableExcelCYM() throws IOException { String companyId = getPara("companyId"); int year = Integer.parseInt(getPara("year")); int month = Integer.parseInt(getPara("month")); String context = "年限:" + year + "月份:" + year + ";公司:" + Company.dao.findFirst("SELECT * FROM `bidb1`.`company` WHERE `id` = ?", companyId).getCompanyname(); Ret result = monthlyReportADDService.StatisticalTableExcelCYM(companyId, year, month); CommonService.me.log(this, "集团报表/集团职能部门报表/单月报表", "导出", context); renderJson(result); }
log公工类的方法:
public void log(Controller controller,String viewPage,String action) { Account loginAccount = controller.getAttr(LoginService.loginAccountCacheName); String loginIp = IpKit.getRealIp(controller.getRequest()); loggerSrv.addLog(loginIp,viewPage,loginAccount,action); } public void log(Controller controller,String viewPage,String action,String context,String jsonBefor,String jsonNow) { Account loginAccount = controller.getAttr(LoginService.loginAccountCacheName); String loginIp = IpKit.getRealIp(controller.getRequest()); loggerSrv.addLog(loginIp,viewPage,loginAccount,action,context,jsonBefor,jsonNow); } /** * 获取两个对象之间的变化(仅对比当前对象写的属性,不会对比父类写的属性) * @param oldBean * @param newBean * @return */ public String getObjectDifferent(Object oldBean, Object newBean) { if (oldBean != null && newBean!= null) { String modifyValue = ""; try { Class clazz = oldBean.getClass(); List<Field> fields = new ArrayList<>(); fields.addAll(new ArrayList<>(Arrays.asList(clazz.getDeclaredFields()))); //如果父类属性变化也记录 fields.addAll(new ArrayList<>(Arrays.asList(clazz.getSuperclass().getDeclaredFields()))); for (Field field : fields) { if ("serialVersionUID".equals(field.getName())) { continue; } PropertyDescriptor pd = new PropertyDescriptor(field.getName(), oldBean.getClass()); Method getMethod = pd.getReadMethod(); Object o1 = getMethod.invoke(oldBean); Object o2 = getMethod.invoke(newBean); if (o1 == null || o2 == null) { continue; } if (!o1.toString().equals(o2.toString())) { modifyValue += field.getName() + ":" + o1 + "->" + o2 + "; "; } } return modifyValue; } catch (Exception e) { e.printStackTrace(); return e.toString(); } } else { //log.info("传入对象为空,保存 “修改操作” 系统敏感操作记录失败"); return "保存 “修改操作” 传入对象为空"; } } public void log(Controller controller,String viewPage,String action,String context) { Account loginAccount = controller.getAttr(LoginService.loginAccountCacheName); String loginIp = IpKit.getRealIp(controller.getRequest()); loggerSrv.addLog(loginIp,viewPage,loginAccount,action,context); }