Need to capture ERROR msg and stack trace

Hi all,

I was hoping someone can point me in the right direction. I'm trying to filter out errors from a web log- any lines with ERROR in it. I know I could simply use the grep command to do this. However, there are times when a stack trace follows the error line. I would like to capture these lines as well. Here is a snippet of the web log:

2006-01-07 18:39:18,212 host123 WARN com.host123 .elf.UserQuest - Quest/option {o.q.more.paper.osc#0} references unknown dependent {t.what.form.file.more.action} in application {src-code}. Please revise.
2006-01-07 18:39:18,212 host123 WARN com.host123 .elf.UserQuest - Quest/option {o.q.more.paper.osc#1} references unknown dependent {t.what.form.file.more.action} in application {src-code}. Please revise.
2006-01-07 18:40:34,281 cessor32 ERROR com.host123 .email.DirectMailer - Unable to connect to server {1.1.1.1}:
javax.mail.MessagingException: Could not connect to SMTP host: 1.1.1.1, port: 25, response: 451
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:996)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:197)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)
at com.host123.email.DirectMailer.deliverMessage(DirectMailer.java:191)
at com.host123.email.DirectMailer.send(DirectMailer.java:153)
at com.host123.webface.util.Notifications.sendEmailX(Notifications.java:126)
at com.host123.webface.util.Notifications.sendEmail(Notifications.java:91)
at com.host123.webface.util.Notifications.sendEmail(Notifications.java:145)
at com.host123.edp.webface.action.DocRecoveryActionProcessor.perform(DocRecoveryActionProcessor.java:81)
2006-01-07 18:43:45,811 host123 WARN com.host123.webface.RequestProcessorImpl - beanId = 7061279 beanTag= Docket , bean is null or unaccessible
2006-01-07 18:43:46,029 host123 WARN com.host123.webface.RequestProcessorImpl - beanId = 7061279 beanTag= Docket , bean is null or unaccessible


I would like to capture only the following lines and redirect the output to a file:

2006-01-07 18:40:34,281 cessor32 ERROR com.host123 .email.DirectMailer - Unable to connect to server {1.1.1.1}:
javax.mail.MessagingException: Could not connect to SMTP host: 1.1.1.1, port: 25, response: 451
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:996)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:197)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)
at com.host123.email.DirectMailer.deliverMessage(DirectMailer.java:191)
at com.host123.email.DirectMailer.send(DirectMailer.java:153)
at com.host123.webface.util.Notifications.sendEmailX(Notifications.java:126)
at com.host123.webface.util.Notifications.sendEmail(Notifications.java:91)
at com.host123.webface.util.Notifications.sendEmail(Notifications.java:145)
at com.host123.edp.webface.action.DocRecoveryActionProcessor.perform(DocRecoveryActionProcessor.java:81)

I was thinking of incorporating some conditional logic, where we filter out lines with ERROR and also any lines thereafter that start with a white space (the stack trace lines start with a tab). Couldn't figure out how to tie that in with grep.

Thanks in advance for any ideas.

gsw

will it help ?

egrep "ERROR|^[       ]*java|^[       ]*at" tracefile

Please note : there is one tab and one space within braces ( for both)

Woohoo!! it works!! :smiley:

Thanks Mahendramahendr, I've been scratching my head on this for sometime!