我的一个项目的 Makefile 在 headless 浏览器上运行一系列测试以执行功能测试步骤。大多数测试都是针对前端代码的,但我也会检查后端是否有任何错误/警告。
目前,我们正在清理 Web 服务器日志,运行所有(非常慢的)测试,然后 grep 服务器日志以查找任何错误或警告。
我想知道是否有任何方法可以让监听器在后台开始解析日志(例如 tail -f | grep
),并在检测到任何错误/警告时终止 make 目标试运行期间。
到目前为止我得到的是
- 在后台启动长期运行的 grep 并存储 PID。
- 运行测试。
- 检查长生命周期 grep 的输出
- 杀死 PID。
- 如果出现任何错误,则失败。
这只给我带来了一个优势,现在我每次都不会丢失开发盒上的服务器日志,因为我不必每次都清理它。但我仍然需要等待很长一段时间(几分钟),因为第一次可能发生的故障。
有什么解决办法吗?
最佳答案
I was wondering if there was any way to have a listener parsing the log (e.g.
tail -f | grep
) starting on the background, and kill the make target if it detects any error/warning during the test run.
您是否尝试过以简单直接的方式进行操作?例如这样:
# make is started somehow, e.g.:
make target >make-target.log 2>&1 &
PIDOFMAKE=$!
# we know its PID and the log file name
tail -f make-target.log | grep 'ERROR!' |
while read DUMMY; do
# error was detected, kill the make:
kill $PIDOFMAKE
break
done
(虽然我不清楚OP在问什么,但我正在写一个答案,因为我无法在评论中放入大量代码。)
关于linux - 在 Makefile 命令后检查日志的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34010848/