Matt RaibleMatt Raible is a Java Champion and Developer Advocate at Okta. developer.auth0.com

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

How To: Configure Log4j to notify you of errors

A couple of weeks ago, I mentioned that I was interested in using Log4j's SMTPAppender to e-mail me messages when errors occured in my webapp. I discovered how easy it is a couple of days ago. Here's how to configure it.

1. Add mail to the log4j.rootCategory in log4j.properties: log4j.rootCategory=INFO, stdout, mail
2. Add the following configuration settings to log4j.properties:

# Configuration for receiving e-mails when ERROR messages occur.
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.To=@ERROR-MAILTO@
log4j.appender.mail.From=@ERROR-MAILFROM@
log4j.appender.mail.SMTPHost=@ERROR-MAILHOST@
log4j.appender.mail.Threshold=ERROR
log4j.appender.mail.BufferSize=1
log4j.appender.mail.Subject=CCT Application Error

log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%p [%t] %C{1}.%M(%L) | %m%n

One question I have is that the ConversionPattern is kinda funky - where the line breaks don't seem to be carried into the e-mail (from exception.printStackTrace()). Any suggestions for a better configuration are appreciated. The To, From, and SMTPHost are all replaced with values from Ant during the build process.

Posted in Java at Jan 30 2003, 06:25:43 AM MST 5 Comments
Comments:

I use the following and line breaks are fine: log4j.appender.Mail.layout=org.apache.log4j.PatternLayout log4j.appender.Mail.layout.ConversionPattern=%d %-5p %c %x - %m%n

Posted by Llucifer on January 30, 2003 at 08:25 AM MST #

where log file will be created ? You have not mention in log4j.properties file the location of log file .

Posted by Rajeev Chaturvedi on November 15, 2007 at 11:40 AM MST #

Thanks

Posted by 202.177.174.81 on December 18, 2008 at 10:09 AM MST #

If you also want to change the subject of the emails received, see Log4J SMTPAppender: Exception info in the subject

Posted by Domaniczky Lajos on October 02, 2009 at 03:01 AM MDT #

Try this: log4j.appender.mail.layout=org.apache.log4j.HTMLLayout

Posted by Steve Wells on March 15, 2010 at 08:55 PM MDT #

Post a Comment:
  • HTML Syntax: Allowed