Wednesday, December 22, 2010

Log4j configuring email in liferay

Its very important to get the email when there an ERROR occurs in our application. So we dont need to search all the logs in the server to check when the error occurs whats the exception thrown.

Liferay version: 5.2.3 - 6.x

Step 1: Configure the log4j.properties

Step 2: Extend the SMTPAppender.java to use the liferay email configuration. By default it uses the SMTPAppender for sending the email. It may throw the error STARTTLS... So for skipping this error I used Liferay Mail Service for sending the email.

Step 3: By default the email is send for the Log Level ERROR and level which has higher priority. So if you need to send the email for particular exception use _log.error(e);

Eg:

public class Abc {
public static void Main(String args[]) {
Log _log = LoggerFactoryUtil.getLog(Abc.class);
_log.error("Its an error. Please fix it soon..");
}

}