From ed1b94ea076fe6f0287e89aa60173b9eaf51ef0f Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Fri, 22 Nov 2013 15:54:22 -0600 Subject: [PATCH] Issue #2359 add ability to ignore messages based on threads, ie ignore shef Change-Id: I51d4b29e7accb3ce5bd90c7478c7f143bd76bb48 Former-commit-id: 4a9f2db86a148b58610680dbd2230b286d89e361 --- .../com.raytheon.uf.logsrv/config.xml | 5 +- .../com/raytheon/uf/logsrv/LogService.java | 2 +- .../uf/logsrv/config/LogSrvConfig.java | 11 +++++ .../uf/logsrv/derby/DerbyAppender.java | 48 +++++++++++++++---- .../raytheon/uf/logsrv/derby/DerbyDao.java | 8 +++- .../uf/logsrv/report/TestReportOutputter.java | 2 +- 6 files changed, 62 insertions(+), 14 deletions(-) diff --git a/javaUtilities/com.raytheon.uf.logsrv/config.xml b/javaUtilities/com.raytheon.uf.logsrv/config.xml index fbb92b122b..d647afea32 100644 --- a/javaUtilities/com.raytheon.uf.logsrv/config.xml +++ b/javaUtilities/com.raytheon.uf.logsrv/config.xml @@ -1,11 +1,12 @@ - ec-redbaron + ec-oma /awips2/edex/data/utility/nate Nathan.Jensen@raytheon.com mk2-msg10.raymail.ray.com 143 awipsctl@list.app.ray.com, awipstest@list.app.ray.com, david_j_hladky@raytheon.com - 01:30 + 00:45 + shefThreadPool \ No newline at end of file diff --git a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/LogService.java b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/LogService.java index c8ebe31790..d36372a456 100644 --- a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/LogService.java +++ b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/LogService.java @@ -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"); diff --git a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/config/LogSrvConfig.java b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/config/LogSrvConfig.java index 3e4bffca58..ed1d540533 100644 --- a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/config/LogSrvConfig.java +++ b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/config/LogSrvConfig.java @@ -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. */ diff --git a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/derby/DerbyAppender.java b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/derby/DerbyAppender.java index 31db60bad7..1b955c9b2d 100644 --- a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/derby/DerbyAppender.java +++ b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/derby/DerbyAppender.java @@ -45,14 +45,46 @@ import com.raytheon.uf.logsrv.StoredMsg; public class DerbyAppender extends AppenderBase { - @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; + } } diff --git a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/derby/DerbyDao.java b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/derby/DerbyDao.java index b6505d2ffb..521d5744be 100644 --- a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/derby/DerbyDao.java +++ b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/derby/DerbyDao.java @@ -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 * diff --git a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/report/TestReportOutputter.java b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/report/TestReportOutputter.java index e954e8ec76..f235ff9d5e 100644 --- a/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/report/TestReportOutputter.java +++ b/javaUtilities/com.raytheon.uf.logsrv/src/com/raytheon/uf/logsrv/report/TestReportOutputter.java @@ -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);