aka*_*ash 0 unix search logging grep tail
在任何类型的服务中,在日志中搜索以下情况的最佳方法是什么:
1 - 如果错误已经发生。
2 - 如果错误被重现并且想要捕获发生的异常/错误。
我知道但效率低下的一些方法是:
tail -f production.log => log flows and you have to check manually.
tail -n1000 production.log => log for last 1000 lines
tail -f production.log | grep '500 Internal Server Error' => shows the flow of log for only one particular line that says 500.
我想打印日志上方的 100 行,以便在这两种情况下也打印回溯(尤其是第二行)。
希望我明白你想要什么。
使用带有 -B 选项的 grep(-B, --before-context=NUM 打印前导上下文的 NUM 行)来告诉在搜索行之前要打印多少行:
在所有日志中查找错误:
grep -B 100 '500 Internal Server Error' production.log
Run Code Online (Sandbox Code Playgroud)
对于实时错误:
tail -f production.log | grep -B 100 '500 Internal Server Error'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7206 次 |
| 最近记录: |