如何从提供的日志中收集相关信息

How to collect the relevant information from the provided log?

本文关键字:信息 日志      更新时间:2023-10-16

我有一个日志文件,我们从中收集了相关数据。考虑日志文件为

--------other data---------------
Evaluating Function Test1 
--other data--
--other data--  
Output: This function excecuted successfully
--------other data---------------
--------other data---------------
Evaluating Function Test2
--other data- 
--other data--  
Output : This function excecuted successfully  
--other data--  
--other data--

我必须收集文件中针对每个函数的所有输出,如

Test1: Output: This function executed successfully

Test2: Output: This function executed successfully

谁能告诉我收集相关数据的方法?

谁能告诉我收集相关数据的方法?

是的(但是你的问题很模糊)。

您的方法必须(大致)遵循以下步骤:

  • 逐行读取文件(有一种规范的方法可以这样做-你会在SO上找到它)
  • 检查每一行,看看是否匹配你感兴趣的模式
  • 将感兴趣的行存储在容器中(如果它们匹配)
  • 解释存储的行(并显示结果)