例如,我有一个像这样的大日志文件:
[2016-02-10 13:17:56.885597] [WARNING] [53171] [src/root/mylinux/test01.cpp:300]
如您所见,此格式包含几个部分:
1. The time stamp, day+hour+minute+second+microsecond
2. Some spaces and the [WARNING] or [ERROR] or [INFO] or [DEBUG], etc.
3. A process ID number like [53171]
4. The source file name + line number
我希望将其格式更改为类似 gcc 错误信息的格式,例如:
test.cpp: In function ‘int main()’:
test.cpp:5: error: ‘pp’ was not declared in this scope
我想使用 VIM+quick fix 导航我的日志文件并跳转到源文件,看看程序是如何执行的。
所以我的要求是:如何使用shell编程或python编程将我的日志文件格式更改为上述gcc错误格式?
谢谢。
请您参考如下方法:
你可以像这样设置 Vim 的 errorformat 选项:
set errorformat+=\[%.%#\]\ \ \ \ \[%m\]\ \ \ \[%.%#\]\ \[%f:%l\]
这应该会为您提供以下结果以及您提供的样本:
提示:您可以执行 $ vim -q mylog 直接在 quickfix 中打开您的日志。
