Merge "Issue #2359 add ability to ignore messages based on threads, ie ignore shef" into development

Former-commit-id: c4baf73e044c156a942290b8be603d9c9621d9fe
This commit is contained in:
Nate Jensen 2013-11-25 08:34:40 -06:00 committed by Gerrit Code Review
commit 38cc0b46f6
6 changed files with 62 additions and 14 deletions

View file

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<logSrvConfig>
<clusterName>ec-redbaron</clusterName>
<clusterName>ec-oma</clusterName>
<databaseDir>/awips2/edex/data/utility/nate</databaseDir>
<fromAddress>Nathan.Jensen@raytheon.com</fromAddress>
<smtpHost>mk2-msg10.raymail.ray.com</smtpHost>
<smtpPort>143</smtpPort>
<toAddress>awipsctl@list.app.ray.com, awipstest@list.app.ray.com, david_j_hladky@raytheon.com</toAddress>
<!-- >toAddress>Nathan.Jensen@raytheon.com</toAddress-->
<timeToSend>01:30</timeToSend>
<timeToSend>00:45</timeToSend>
<ignoreThreads>shefThreadPool</ignoreThreads>
</logSrvConfig>

View file

@ -73,7 +73,7 @@ public class LogService {
LogSrvConfig config = (LogSrvConfig) m.unmarshal(new File(
SERVICE_CONFIG));
config.validate();
DerbyDao.setConfig(config);
DerbyDao.getInstance().setConfig(config);
logger.info("Logging events from " + config.getClusterName());
logger.info("Starting socket listener");

View file

@ -68,6 +68,9 @@ public class LogSrvConfig {
@XmlElement
private String timeToSend;
@XmlElement
private String ignoreThreads;
public String getFromAddress() {
return fromAddress;
}
@ -124,6 +127,14 @@ public class LogSrvConfig {
this.databaseDir = databaseDir;
}
public String getIgnoreThreads() {
return ignoreThreads;
}
public void setIgnoreThreads(String ignoreThreads) {
this.ignoreThreads = ignoreThreads;
}
/**
* Validates that the config has every value set.
*/

View file

@ -45,14 +45,46 @@ import com.raytheon.uf.logsrv.StoredMsg;
public class DerbyAppender extends AppenderBase<ILoggingEvent> {
@Override
protected void append(ILoggingEvent eventObject) {
StoredMsg msg = new StoredMsg(eventObject);
try {
DerbyDao.getInstance().insert(msg);
} catch (LogServiceException e) {
LogService.getLogger().error(
"Error inserting message into derby database", e);
private DerbyDao dao;
private String[] ignoreThreads;
public DerbyAppender() {
super();
dao = DerbyDao.getInstance();
String ignore = dao.getConfig().getIgnoreThreads();
if (ignore != null) {
ignoreThreads = ignore.split(",");
}
}
@Override
protected void append(ILoggingEvent eventObject) {
if (shouldStoreMsg(eventObject)) {
StoredMsg msg = new StoredMsg(eventObject);
try {
dao.insert(msg);
} catch (LogServiceException e) {
LogService.getLogger().error(
"Error inserting message into derby database", e);
}
}
}
/**
* Checks whether or not the appender should store the logging event
*
* @param event
* @return
*/
private boolean shouldStoreMsg(ILoggingEvent event) {
if (ignoreThreads != null) {
for (String ignore : ignoreThreads) {
if (event.getThreadName().startsWith(ignore)) {
return false;
}
}
}
return true;
}
}

View file

@ -94,7 +94,7 @@ public class DerbyDao {
private static DerbyDao instance = new DerbyDao();
private static LogSrvConfig config;
private LogSrvConfig config;
private DerbyDao() {
@ -104,10 +104,14 @@ public class DerbyDao {
return instance;
}
public static void setConfig(LogSrvConfig cfg) {
public void setConfig(LogSrvConfig cfg) {
config = cfg;
}
public LogSrvConfig getConfig() {
return config;
}
/**
* Creates a connection to derby
*

View file

@ -57,7 +57,7 @@ public class TestReportOutputter {
LogSrvConfig config = (LogSrvConfig) m
.unmarshal(new File("config.xml"));
config.validate();
DerbyDao.setConfig(config);
DerbyDao.getInstance().setConfig(config);
LogReportContainer container = DerbyDao.getInstance().buildReport();
String report = HtmlGenerator.generateHtml(container);
ReportEmailer.email(report, config);