跳到内容
SCRM DOC
创建于2024-11-14更新于 2025-03-22

日志注解@AutoLog

jeecg-boot 提供了在线日志管理功能,可以在线实时查看系统登录更新的所有操作。 jeecg-boot 提供两种方式,写入系统日志

方式一: 自定义注解@AutoLog 在 Control 的方法上,加上注解@AutoLog(" 操作内容描述 ") 参考:

     /**
	 *   添加
	 * @param jeecgDemo
	 * @return
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@AutoLog(value = "添加测试DEMO")
	public Result<JeecgDemo> add(@RequestBody JeecgDemo jeecgDemo) {
		Result<JeecgDemo> result = new Result<JeecgDemo>();
		try {
			jeecgDemoService.save(jeecgDemo);
			result.success("添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
			log.info(e.getMessage());
			result.error500("操作失败");
		}
		return result;
	}

复制

方式二: 调用共通 API 插入日志(新版)

a. 引入共通 service

@Autowired
private BaseCommonService  baseCommonService  ;

复制

b. 调用插入日志方法

baseCommonService.addLog("登录失败,用户名:"+username+"不存在!", CommonConstant.LOG_TYPE_1, null);

复制

本页目录