1.進入日志目錄下[具體目錄看項目]
cd /home/admin/fmg/logs/
2.打開日志
more info.2020-09-01.log
或
tail -100 info.2020-09-01.log
得到結果:
2020-09-01 10:09:49:656 WARN t.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'ISchoolDao' and 'com.lexue.operation.repository.ISchoolDao' mapperInterface. Bean already defined with
the same name!
2020-09-01 10:09:49:656 WARN t.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'IRefundLogDao' and 'com.lexue.operation.repository.IRefundLogDao' mapperInterface. Bean already define
d with the same name!
2020-09-01 10:09:49:656 WARN t.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'IOrderLogsDao' and 'com.lexue.operation.repository.IOrderLogsDao' mapperInterface. Bean already define
d with the same name!
所以按日期截取格式為:【XXXX-XX-XX XX:XX:XX】
more/tail 命令, ctrl+c 可退出
3.執行截取命令
sed -n '/2020-09-01 10:00/, /2020-09-01 10:10/p' /home/admin/fmg/logs/info.2020-08-26.log > /home/fj/online-bug.log
sed -n '/開始時間/,/結束時間/p' 日志所在目錄 > 截取新生成日志文件目錄
注意:
開始時間,結束時間一定要注意是 日志文件中可以找到的,否則無法導出
例如:我的日志文件:info.2020-08-26.log 中全文檔搜索沒有找到 “2020-09-01 10:09:49:000” ,我現在使用sed -n '/2020-09-01 10:09:49:000/, /2020-09-01 11:09:49:000/p' /home/admin/fmg/logs/info.2020-08-26.log > /home/fj/online-bug.log
導出的日志文件為空,即使這個時間段內有日志,所以截取時要注意時間點,可以擴大到秒,分,時,天;
所以按分sed -n '/2020-09-01 10:00/, /2020-09-01 11:09/p' /home/admin/fmg/logs/info.2020-08-26.log > /home/fj/online-bug.log
; 按時sed -n '/2020-09-01 10/, /2020-09-01 11/p' /home/admin/fmg/logs/info.2020-08-26.log > /home/fj/online-bug.log
當然前提都是這個時間點在日志文件中可以被搜索到