思路
日志采用新增模式记录,不做更新、删除操作,保留所有操作记录具有可溯源性。同时,为了方便使用,封装一个方法记录日志,在需要记录日志处调用该方法,传入需要的参数即可进行日志记录。所以,需要在建表时,考虑到字段的通用性;在编写记录方法时,需要考虑方法的通用性。
表结构
字段:
- Log_Uuid :String(200) Key 日志唯一 编码;这个字段作为整张表的唯一key,采用UUID模式;
- Log_TypeCode :String(100) Key 日志类型编码;此字段用于区别不同日志记录,例如是用人需求申请接口日志,还是转正申请接口日志等;
- Log_TypeDescr:String(200) 日志类型描述;
- Log_Interface_num:String(100) 针对接口类型日志的字段,主要用于记录接口的流水号;
- Emplid:记录员工ID,针对接口类型日志的字段,主要用于记录请求员工或操作接口的员工ID;
- Log_Status String(10):针对接口类型日志的字段,主要用于记录接口请求返回的网络状态值,例如:200,404,500等;
- Request_JsonBody :Long 针对接口类型日志的字段,主要用于记录接口的请求JSON文本;
- Response_JsonBody:Long 针对接口类型日志的字段,主要用于记录接口的返回JSON文本;
- Log_Body:Long 针对普通日志记录,主要记录程序运行期间打的断点记录;
- Log_String1:备用字段1,用于需要特殊记录的字段;
- LastUpddttm : DateTime 上次操作时间;时间戳,精确值最好采用精确到毫秒级别;
- LastUpOprid:String(30) 操作用户;
通用方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
Function DoCustomerLog(&uuid, &typeCode, &typeDescr, &interfaceNum, &emplid, &status, &requsetBody, &responseBody, &logBody, &string1) Returns string Local string &strReturn; try Local Record &recLog = CreateRecord(Record.C_CUSTOMER_LOG); &recLog.LOG_UUID.Value = &uuid; &recLog.LOG_TYPECODE.Value = &typeCode; If Not (&recLog.SelectByKey()) Then &recLog.LOG_UUID.Value = &uuid; &recLog.LOG_TYPECODE.Value = &typeCode; &recLog.LOG_TYPEDESCR.Value = &typeDescr; &recLog.LOG_INTERFACE_NUM.Value = &interfaceNum; &recLog.EMPLID.Value = &emplid; &recLog.LOG_STATUS.Value = &status; &recLog.REQUEST_JSONBODY.Value = &requsetBody; &recLog.RESPONSE_JSONBODY.Value = &responseBody; &recLog.LOG_BODY.Value = &logBody; &recLog.LOG_STRING1.Value = &string1; &recLog.LASTUPDDTTM.Value = %Datetime; &recLog.LASTUPDOPRID.Value = %OperatorId; &recLog.Insert(); End-If; catch Exception &ex &strReturn = &ex.ToString(); end-try; Return &strReturn End-Function;
|
调用方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Declare Function DoCustomerLog PeopleCode C_CUSTOMER_LOG.LOG_UUID FieldFormula;
Local string &strUuid = UuidGen(); Local string &strTypeCode = "C_INTERFACE_CODE1"; Local string &strTypeDescr = "测试接口1"; Local string &strInterfaceNum = "2021_1_2_OA_1000000001"; Local string &stremplid = "AK700075"; Local string &strStatus = "200"; Local string &requestBody = "akjhdgl;ajgl;jalkdsghl;akdsglk;alk;dghl;akhgjkfakjbnilfdjghkashdg"; Local string &responseBody = "akjhdgl;ajgl;jalk1234567898765432345yufjnfjghjfnh00000000000000000jbnilfdjghkashdg"; Local string &logBody = " "; Local string &string1 = " ";
Local string &strReturn = DoCustomerLog(&strUuid, &strTypeCode, &strTypeDescr, &strInterfaceNum, &stremplid, &strStatus, &requestBody, &responseBody, &logBody, &string1);
|