ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

linux 查询某个时间段的日志

2019-10-25 11:50:52  阅读:208  来源: 互联网

标签:11 10 http nio INFO 12129 时间段 linux 日志


目前因发生了异常大概记得发生的时间段,想查看这个时间段的日志

  • 如我们的日志格式如下
  • 1:09:59.946 [http-nio-12129-exec-10] INFO  ntroller start ====
    11:09:59.946 [http-nio-12129-exec-10] INFO  .BannerInfoService -  ===== getBannerInfoList start==========
    11:09:59.947 [http-nio-12129-exec-10] INFO  vice.BannerInfoService -  ===== getBannerInfoList end==========
    11:09:59.947 [http-nio-12129-exec-10] INFO  .controller.DriverBaseController - ==== GetBannerInfoController end ====
    11:09:59.947 [http-nio-12129-exec-10] INFO  er.a
  • 因为我们的日志是日期是不显示年月的,所以使用时分秒进行查询
  • sed -n '/11:10:00/,/11:10:20/p' dongfeng-driver-core.2019-10-25.log
    • 注意的部分:

      1. 开始时间和结束时间必须是日志里面有的,要是没有开始的时间,那就是查找没有结果,要是没有结束时间,查询的结果就是开始时间到最后的全部日志
      2. 时间后面的p不能省略

  • 模糊查询(按分钟和按小时):
  • sed -n '/11:10:*/,/11:20*/p' dongfeng-driver-core.2019-10-25.log
  • 结合grep一起使用(比如我要找到超时的日志)
  • sed -n '/11:10:*/,/11:20*/p' dongfeng-driver-core.2019-10-25.log | grep 超时
    • $ sed -n '/11:10:*/,/11:20*/p' dongfeng-driver-core.2019-10-25.log | grep 超时
      11:10:20.895 [http-nio-12129-exec-2] INFO allFeign - feign response body : HttpCommandResultWithData{data=null} CommonResult{resultCode=408, message='请求超时'}
      11:10:20.896 [http-nio-12129-exec-2] INFO cAop - RESPONSE : HttpCommandResultWithData{data=null} CommonResult{resultCode=408, message='请求超时'}
      11:16:26.696 [http-nio-12129-exec-1] INFO coForCallFeign - feign response body : HttpCommandResultWithData{data=null} CommonResult{resultCode=408, message='请求超时
  • 最后一步日志导出
    • sed -n '/11:10:*/,/11:20*/p' dongfeng-driver-core.2019-10-25.log > 11.txt
    • 导出到当前目录 ll查看一下当前目录是否存在
  • total 31172

    -rw-rw-r-- 1 prodfcv1 prodfcv1 14608 Oct 25 11:35 11.txt
    drwxrwxr-x 2 prodfcv1 prodfcv1 6 May 6 2018 baklog

标签:11,10,http,nio,INFO,12129,时间段,linux,日志
来源: https://www.cnblogs.com/jiyanjiao-702521/p/11737235.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有