Linux

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > Linux > linux查看错误日志

linux中如何查看错误日志

作者:hammring

在Linux部署JAR包后,可通过查看日志定位错误,使用grep命令过滤error信息,egrep和fgrep为扩展功能变体,动态监控日志时,结合tail -f与grep更高效,方便排查问题,此为个人经验分享

linux查看错误日志

将jar包部署到服务器,程序在跑了一段时间后发现日志报错。然后想要找到具体报错的地方。

先查看日志,然后用管道通道符查找日志中有error的字段。

cat xxx.log | grep ERROR ## | 为管道符 

grep

命名:

grep,egrep,fgrep -print line mathing a pattern (打印匹配行的一种方法)

描述:

searches the named input files for lines containing a match to the given pattern.by default,grep prints the matching lines.(与输入文件的行中包含的某一字段进行匹配,grep默认打印的是匹配行的内容)

in addition,two variant programs egrep and fgrep are available.egrep is the same as grep -E.fgrep is the same as grep -F.Direct invocation as either egrep or fgrep is deprecated.but is provided to allow historical applications that rely on then to run unmodified.(另外,两个变量egrep和fgrep是可获得的,egrep等同于grep -E,fgrep等同于grep-F。直接调用egrep和fgrep是过时的,但是允许依赖历史性的应用程序不加修改地执行)

可选项:

-E  --extended-regexp 

Interpret pattern as an extended regular expression.(这一模式意思是一个扩展的正则表达式)

-F --fixed-strings, --fixed-regexp

Interpret pattern as a list of fixed strings,seperated by newlines.any of which is to be extended.(这一模式的意思是一个可变长字符串的列表。通过新的行分开,列表里边的任何一个都可以去被扩展)

动态查看日志的命令

tail -f xxx.log

然后发现该命令打印日志报错的信息查看起来不是很方便,

很难去具体排查出错的地方可通过输入以下的命令:

grep xxx.log -e ERROR ##xxx.log为日志的文件名 ERROR为日志中的出现ERROR的字段

这样就会在linux中显示日志具体的报错时间和具体报错的内容。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文