业务日志记录规范

编程入门 行业动态 更新时间:2024-10-09 13:30:19

<a href=https://www.elefans.com/category/jswz/34/1768917.html style=业务日志记录规范"/>

业务日志记录规范

目的

使用规范的日志格式,方便后续阿里云日志服务查询分析

阿里云日志服务简介

日志服务提供大规模日志实时查询与分析能力(LogSearch/Analytics),开启索引后,可以对日志数据进行统计与查询。

查询分析语句格式

对采集到的日志数据进行实时查询分析时,需要输入查询分析语句(Query)。

查询语句(Search)和分析语句(Analytics)两个部分组成,查询和分析语句之间通过 |进行分割。

$Search |$Analytics

查询语句底层是搜索,所以必须对日志的字段开启索引并设置分词符;分析语句则与sql类似。默认的分词符如下:

, '";=()[]{}?@&<>/:\n\t\r

参考链接:.html?spm=5176.2020520112.0.0.9a0934c0mbzPdN

日志格式一(json格式)
{"eventTime":1545097873111,"traceId":254693851674057480,"memId":12345678,"trueName":"张三","mobile":"13800138000","email":"12345678@xx","dept":null,"job":"其他","customerId":123456,"customerName":"XXX有限责任公司","spId":1,"spName":"世强","behaviorType":"收藏","infoId":75036948,"businessData":{"brandName":"Renesas","detailUrl":".html","title":"【产品】瑞萨发布新型全塑封型数字 DC/DC PMBus™ 电源模块RAA210xxx ,提供先进的数字通讯和监测功能","content":"收藏了 【产品】瑞萨发布新型全塑封型数字 DC/DC PMBus™ 电源模块RAA210xxx ,提供先进的数字通讯和监测功能"},"logType":null}
示例一:获取Json任意一级的某个key值
__topic__: srms and class: AddServiceRecordConsumer and ml: "handleDelivery:31" and msg: brandName | 
SELECT msg, json_extract_scalar(json_parse(substr(msg, 24)), '$.businessData.brandName') as brandName

示例二:根据某一个key分组统计
__topic__: srms and class: AddServiceRecordConsumer and ml: "handleDelivery:31" and msg: brandName | 
SELECT json_extract_scalar(json_parse(substr(msg, 24)), '$.businessData.brandName') as brandName, COUNT(*) as count
GROUP BY brandName ORDER BY count DESC

日志格式二(key、value格式)
key1=value1,key2=value2 ...
说明
  • 等于号、逗号是默认的分词符,日志经过分词后,通过key1/value1/key2/value2可以查询到该日志
  • 同一个项目里面,key必须是唯一的,且只能是英文,区分大小写,可以使用驼峰式命名的方法
  • key与标点符号之间,value与标点符号之间不要有空格
  • 某些情况如需使用模糊查询,只能是右模糊查询。例如key为abc,通过ab*也可以查询到该日志,但是不能使用*b**bc
使用示例
Java代码
logger.info("downloadDocSentEmailMemberId={},isDownloadEmail={}", shareLogDI.getMemberId(), shareLogDI.getIsDownloadEmail());
示例一:日志转换成map
(__topic__: portal or __topic__: appGate) and msg: downloadDocSentEmailMemberId | 
select split_to_map(msg, ',', '=')

示例二:根据某一个key分组统计
(__topic__: portal or __topic__: appGate) and msg: downloadDocSentEmailMemberId | 
select split_to_map(msg, ',', '=')['downloadDocSentEmailMemberId '] as memberId, count(*) as count GROUP BY memberId ORDER BY count DESC

示例三:遍历map,一行拆成多行
(__topic__: portal or __topic__: appGate) and msg: downloadDocSentEmailMemberId | 
select key, value from log, unnest (split_to_map(msg, ',', '=')) as t(key, value)

更多推荐

业务日志记录规范

本文发布于:2024-02-06 07:30:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1746996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:业务   日志

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!