在Linux/UNIX上分析程序日志的技巧(3)

第一步:定位出现异常的行, java 的异常,通常包含 Exception 字样

grep -n "Exception" catalina.out

该指令的 -n 参数会打印符合条件的行的行号,示例输出如下:

[itims@localhost logs]$ grep -n "Exception" catalina.out

33642:java.lang.NullPointerException

33910:java.lang.NullPointerException

34213:java.lang.NullPointerException

34523:java.lang.NullPointerException

34597:java.lang.NullPointerException

第二步 : 截取 Exception 所在行的前后各 10 行。

比如我们想关注 33910 行的 NullPointerException , 可以用如下指令 :

head -33920 catalina.out | tail -20

该指令会得到如下输出 :

[itims@localhost logs]$ head -33920 catalina.out | tail -20

Asia/Shanghai

CN

/usr/local/jdk1.5.0_12/jre

Thu Sep 17 11:13:00 GMT+08:00 2009

17 Sep 2009 03:13:00 GMT

2009-9-17 11:13:00

2009-09-17 11:13:00

java.util.GregorianCalendar[time=1253157180432,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+08:00",offset=28800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=8,WEEK_OF_YEAR=38,WEEK_OF_MONTH=3,DAY_OF_MONTH=17,DAY_OF_YEAR=260,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=11,HOUR_OF_DAY=11,MINUTE=13,SECOND=0,MILLISECOND=432,ZONE_OFFSET=28800000,DST_OFFSET=0]

null

java.lang.NullPointerException

at itims.share.db.GlobalTransaction.rollback(GlobalTransaction.java:125)

at itims.web.frmwk.NetElementService.deleteNetelement(NetElementService.java:292)

at org.apache.jsp.frmwk.deletene_jsp._jspService(deletene_jsp.java:77)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/27777.html