加入收藏 | 设为首页 | 会员中心 | 我要投稿 西安站长网 (https://www.029zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 建站 > 正文

架构师必看!操作日志系统搭建秘技

发布时间:2019-07-05 04:33:12 所属栏目:建站 来源:程序员进阶架构师
导读:副标题#e# 在Java开发中,我们经常会遇到一个棘手的问题:记录用户的操作行为。 某些操作是相对简单的,我们可以逐条记录。但是某些操作行为却很难记录,例如编辑操作。在某一次操作中,用户可能编辑了对象A的几个属性,而下一次操作中用户可能编辑了对象B

则我们可以使用下面查询条件:

  1. http://{your_ObjectLogger_address}/ObjectLogger/log/query?appName=myBootApp&objectName=TaskModel&objectId=9 

查询到如下结果:

  1.  "respMsg": "成功", 
  2.  "respData": [ 
  3.  { 
  4.  "id": 15, 
  5.  "appName": "myBootApp", 
  6.  "objectName": "TaskModel", 
  7.  "objectId": 9, 
  8.  "actor": "actor name", 
  9.  "action": "editTask", 
  10.  "actionName": "edit Task", 
  11.  "extraWords": "via app", 
  12.  "comment": "some comments", 
  13.  "actionTime": "2019-04-10T10:56:17.000+0000", 
  14.  "actionItemModelList": [ 
  15.  { 
  16.  "id": 18, 
  17.  "actionId": 15, 
  18.  "attributeType": "NORMAL", 
  19.  "attribute": "taskName", 
  20.  "attributeName": "TASK", 
  21.  "oldValue": "oldName", 
  22.  "newValue": "newName", 
  23.  "diffValue": null 
  24.  }, 
  25.  { 
  26.  "id": 19, 
  27.  "actionId": 15, 
  28.  "attributeType": "USERID", 
  29.  "attribute": "userId", 
  30.  "attributeName": "USER", 
  31.  "oldValue": "USER:3", 
  32.  "newValue": "USER:5", 
  33.  "diffValue": "diffValue" 
  34.  }, 
  35.  { 
  36.  "id": 20, 
  37.  "actionId": 15, 
  38.  "attributeType": "TEXT", 
  39.  "attribute": "description", 
  40.  "attributeName": "DESCRIPTION", 
  41.  "oldValue": ""t<p>the first line</p>nt<p>the second line</p>nt<p>the 3th line</p>"", 
  42.  "newValue": ""t<p>the first line</p>nt<p>the second line</p>nt<p>the last line</p>"", 
  43.  "diffValue": "第6行变化:<br/> -:<del> the 3th line </del> <br/> +:<u> the last line </u> <br/>" 
  44.  } 
  45.  ] 
  46.  } 
  47.  ], 
  48.  "respCode": "1000" 

6 对象属性过滤

有些对象的属性的变动不需要进行日志记录,例如updateTime、hashCode等。ObjectLogger支持对对象的属性进行过滤,只追踪我们感兴趣的属性。

并且,对于每个属性我们可以更改其记录到ObjectLogger系统中的具体方式,例如修改命名等。

要想启用这个功能,首先将配置中的object.logger.autoLog改为false。

  1. object.logger.autoLog=false 

然后在需要进行变化日志记录的属性上增加@LogTag注解。凡是没有增加该注解的属性在日志记录时会被自动跳过。

(编辑:西安站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读