zoukankan      html  css  js  c++  java
  • linux命令-日志查看

    https://www.cnblogs.com/kbkiss/p/7567725.html

    查看日志常用命令

    tail命令

       -n  是显示行号;相当于nl命令;例子如下:
           ` tail -100f test.log `     实时监控100行日志
           ` tail  -n  10  test.log `   查询日志尾部最后10行的日志;
    
           ` tail -n +10 test.log `   查询10行之后的所有日志;
    

    cat命令

    (1) cat -n system.log | grep "debug" -C 100 找到关键日志并向下输出一百行
    (1) cat -n system.log | grep "debug" -C 100 找到关键日志并向上输出一百行

    应用场景一:按行号查看---过滤出关键字附近的日志

    步骤 :
    (1) cat -n test.log |grep "debug" 得到关键日志的行号
    (2) cat -n test.log |tail -n +92|head -n 20 选择关键字所在的中间一行. 然后查看这个关键字前10行和后10行的日志:

    `tail -n +92`表示查询92行之后的日志
    
     `head -n 20 `则表示在前面的查询结果里再查前20条记录
    

    应用场景二:根据日期查询日志

    (1) 方法一
    sed -n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p' test.log

      特别说明:上面的两个日期必须是日志中打印出来的日志,否则无效;
    
      先 grep '2014-12-17 16:17:20' test.log 来确定日志中是否有该 时间点
    

    (2) 方法二

    2020-09-24 14:31:06.478 [http-nio-12002-exec-1][] DEBUG - org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning
    cached instance of singleton bean 'propertyConfigurer'
    2020-09-24 14:31:06.481 [http-nio-12002-exec-1][] DEBUG - org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning
    cached instance of singleton bean 'messageSource'
    
    

    假如我们的日志格式是这样的,

    grep '2020-09-24 14:31:[0-3]' system.log |
    
    

    这里使用查询条件使用了正则表达式,表示获取 2020-09-24 14:31:00 开始的时间到 2020-09-24 14:31:39 的结束时间的日志

    应用场景三:日志内容特别多,打印在屏幕上不方便查看

    (1)使用more和less命令,
    
           如:` cat -n test.log |grep "debug" |more`     这样就分页打印了,通过点击空格键翻页
    
    (2)使用 >xxx.txt 将其保存到文件中,到时可以拉下这个文件分析
    
            如:`cat -n test.log |grep "debug"  >debug.txt`
  • 相关阅读:
    js正则表达式 (.+)与(.+?)
    javaScript中的继承
    理解javascript中event loop,
    vue3-provide/inject 注入
    javaScript设计模式
    javaScript语言精粹--函数
    vue在数据data里面引入图片语法是require("")
    查看分支
    vue项目里面预览下载附件
    小程序组件中传值的几种方式
  • 原文地址:https://www.cnblogs.com/Benjious/p/13724599.html
Copyright © 2011-2022 走看看