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.(这一模式的意思是一个可变长字符串的列表。通过新的行分开,列表里边的任何一个都可以去被扩展)

然后发现该命令并没有打印日志报错的时间,很难去具体排查出错的地方然后通过输入以下的命令:

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

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章