Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Setup error notification via smtp appender #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion assets/config/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@
</layout>
</appender>

<appender name="gmail" class="org.apache.log4j.net.SMTPAppender">
<param name="Bcc" value=""/>
<param name="BufferSize" value="512"/>
<param name="Cc" value=""/>
<param name="LevelMax" value="FATAL"/>
<param name="LevelMin" value="ERROR"/>
<param name="From" value="[email protected]"/>
<param name="enable" value="true"/>
<param name="SMTPDebug" value="TRUE"/>
<param name="SMTPHost" value="smtp.gmail.com"/>
<param name="SMTPPassword" value="mfblelhwkvtatdpi"/>
<param name="SMTPPort" value="465"/>
<param name="SMTPProtocol" value="smtps"/>
<param name="auth" value="true"/>
<param name="SMTPUsername" value="[email protected]"/>
<param name="Subject" value="OpenSRP Server :: Exception Notification :: User ${user.name}"/>
<param name="threshold" value="ERROR"/>
<param name="To" value="[email protected]"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n"/>
</layout>
</appender>

<logger name="org.motechproject">
<level value="WARN"/>
</logger>
Expand Down Expand Up @@ -73,8 +96,9 @@

<root>
<priority value="INFO"/>
<!--<appender-ref ref="RollingLog"/>-->
<!-- <appender-ref ref="RollingLog"/> -->
<appender-ref ref="CONSOLE"/>
<appender-ref ref="gmail"/>
</root>

</log4j:configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.io.IOUtils;
import org.opensrp.common.util.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;

Expand All @@ -24,6 +26,8 @@
@Component
public class HttpUtil {

private static Logger logger = LoggerFactory.getLogger(HttpUtil.class.toString());

public HttpUtil() {
}

Expand Down Expand Up @@ -52,6 +56,7 @@ public static HttpResponse post(String url, String payload, String data, String
return new HttpResponse(con.getResponseCode() == HttpStatus.SC_OK, IOUtils.toString(con.getInputStream()));

} catch (Exception e) {
logger.error(HttpUtil.class.toString(), e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public FormSubmission convert(FormSubmissionDTO submission) {
addFormToOpenMRS(formSubmission);
}
catch(Exception e){
logger.error(this.getClass().getName(), e);
e.printStackTrace();
ErrorTrace errorTrace=new ErrorTrace(new Date(), "Parse Exception", "", e.getStackTrace().toString(), "Unsolved", formSubmission.formName());
errorTrace.setRecordId(formSubmission.instanceId());
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
</dependencies>

<build>
<!-- <pluginManagement> -->
<plugins>
Expand Down