业务日志记录规范

目的

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

阿里云日志服务简介

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

查询分析语句格式

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

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

$Search |$Analytics

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

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

参考链接:https://help.aliyun.com/document_detail/43772.html?spm=5176.2020520112.0.0.9a0934c0mbzPdN

日志格式一(json格式)
{"eventTime":1545097873111,"traceId":254693851674057480,"memId":12345678,"trueName":"张三","mobile":"13800138000","email":"12345678@xx.com","dept":null,"job":"其他","customerId":123456,"customerName":"XXX有限责任公司","spId":1,"spName":"世强","behaviorType":"收藏","infoId":75036948,"businessData":{"brandName":"Renesas","detailUrl":"https://www.sekorm.com/news/75036948.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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值