记录一下,排查日志的操作步骤:
1. 查看重连日志
cat test.json
结果:
{"time": 1617217365, "msg": "断线重连", "count": 1}
{"time": 1617225128, "msg": "断线重连", "count": 1}
{"time": 1617228095, "msg": "断线重连", "count": 1}
2. 查看内容符合的日志
grep "1617217364" xrpusdt.json -n
结果:
41224:{"time": 1617217364520, "price": 0.55343}
备注: 一开始日志时间如果查不到,就查查附近的秒数有没有,减少1秒,就查到了
41224 就是行数
3. 查看排查到的行数的附近日志:
tail -n +41220 xrpusdt.json |head -n 10
{"time": 1617217360525, "price": 0.55342}
{"time": 1617217361533, "price": 0.55342}
{"time": 1617217362566, "price": 0.55348}
{"time": 1617217363574, "price": 0.55344}
{"time": 1617217364520, "price": 0.55343}
{"time": 1617217368519, "price": 0.55338}
{"time": 1617217369531, "price": 0.55331}
{"time": 1617217370568, "price": 0.55333}
{"time": 1617217371575, "price": 0.55336}
{"time": 1617217372616, "price": 0.55336}
备注: 利用tail、head 命令 ,就能显示日志指定行数的前后内容了。
4. 或者可以使用 sed 命令
sed -n "41220,41228p" xrpusdt.json
{"time": 1617217360525, "price": 0.55342}
{"time": 1617217361533, "price": 0.55342}
{"time": 1617217362566, "price": 0.55348}
{"time": 1617217363574, "price": 0.55344}
{"time": 1617217364520, "price": 0.55343}
{"time": 1617217368519, "price": 0.55338}
{"time": 1617217369531, "price": 0.55331}
{"time": 1617217370568, "price": 0.55333}
{"time": 1617217371575, "price": 0.55336}
好了,笔记记录完毕,以后类似的查找关键字日志及其前后日志都可以按照此步骤排查。