0

Struggling with finding a solution to the pain of having to constantly access my server, load the catalina.out file, and wade through the mess to find exceptions. What are developers using to constantly monitor the tomcat catalina.out file and send an email when an exception is found? I'd also be ok with some guidelines towards writing my own shell script to accomplish this. If shell scripting would be powerful enough for this type of thing.

My server is debian/ubuntu. I'm using Tomcat 7.

Note: I came across logwatch, but on initial review it doesn't seem to support tomcat without customizing, and it doesn't appear to be able to sniff out exceptions in the catalina.out file, and it doesn't appear to be a utility to monitors in real time. I'd rather not wait until the end of the day to learn about catastrophic exceptions that may be occuring.

Additional Note: I do plan on implementing something like log4j in the future, but at the moment I am looking for a quicker alternative. Something that doesn't require me updating all my exception handling code.

ryandlf
  • 27,155
  • 37
  • 106
  • 162

3 Answers3

1

If you are using log4j you can just use the SMTP appender for error level ERROR. See the documentation for more information. I have used this with Tomcat in the past and it worked great.

Also, this answer has a full example of using the SMTP appender to send emails.

Community
  • 1
  • 1
AlexC
  • 1,395
  • 14
  • 26
  • I mentioned that would be coming in the future but it requires a bit of work and I wanted a quick solution. That being said, its possible that just doing said work would be easier. – ryandlf Jul 11 '15 at 18:52
  • It is a good solution and compatible with Logger interface, so best case is you will have a drop in conversion, worst case you may need to rewrite some logging statements. Either way, you will get the email appender for free in the process. – AlexC Jul 11 '15 at 19:45
0

purchase an account with www.newrelic.com, add their monitoring to your app (which is easy for tomcat), and get their alert mechanism configured to send you email on error https://docs.newrelic.com/docs/alerts.

Chii
  • 14,540
  • 3
  • 37
  • 44
  • To be honest newrelic (or a similar service) is probably what I will end up with down the road. At the moment though i'm looking for something that "does a little less." I simply want to constantly poll the catalina.out for exceptions of any sort, and then email those notifications to a specified email address. – ryandlf Jul 11 '15 at 17:27
0

Disclaimer: I'm a content developer for MailHandler included with JavaMail project.

For java.util.logging you can use MailHandler included with JavaMail. Download the JavaMail reference implementation jar file and modify the tomcat startup script include JavaMail in the Tomcat bootstrap ClassLoader. Then modify the logging.properties file to install the MailHandler. Here is a sample configuration:

handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler, com.sun.mail.util.logging.MailHandler

.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler, com.sun.mail.util.logging.MailHandler


com.sun.mail.util.logging.MailHandler.subject=com.sun.mail.util.logging.CollectorFormatter
com.sun.mail.util.logging.MailHandler.level=WARNING
com.sun.mail.util.logging.MailHandler.pushLevel=WARNING
com.sun.mail.util.logging.MailHandler.pushFilter=com.sun.mail.util.logging.DurationFilter
com.sun.mail.util.logging.MailHandler.mail.host=some-smtp-host
com.sun.mail.util.logging.MailHandler.authenticator=some-password
com.sun.mail.util.logging.MailHandler.mail.from=app@server.com
#com.sun.mail.util.logging.MailHandler.mail.sender=team@list.com
com.sun.mail.util.logging.MailHandler.mail.to=devs@bugfixers.com
com.sun.mail.util.logging.MailHandler.verify=resolve
com.sun.mail.util.logging.MailHandler.mail.smtp.quitwait=false
com.sun.mail.util.logging.MailHandler.mail.smtp.connectiontimeout=45000
com.sun.mail.util.logging.MailHandler.mail.smtps.connectiontimeout=45000
com.sun.mail.util.logging.MailHandler.mail.smtp.timeout=45000
com.sun.mail.util.logging.MailHandler.mail.smtps.timeout=45000
jmehrens
  • 10,580
  • 1
  • 38
  • 47