Skip to content

Commit

Permalink
Add support for java log formats
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfee-usgs committed Apr 7, 2016
1 parent c232021 commit 4cf227a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions etc/documentation/userguide/changeLog.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ <h2>Version 1.10.1 2016-04-07</h2>
ProductBuilder (which includes EIDSInputWedge) or CLIProductBuilder</li>
<li>Update moment tensor indexer module to use derived-magnitude-type
property.</li>
<li>Add support for java's "simple" and "xml" log formatters
(as an alternative to the default "pdl" formatter).</li>
</ul>

<h2>Version 1.10.0 2016-02-11</h2>
Expand Down
6 changes: 5 additions & 1 deletion etc/documentation/userguide/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ <h3>Global Properties</h3>
the "logfile" property.</em>
</dd>

<dt>logformat</dt>
<dd>format for logs.
Possible values are "pdl" (default), "simple", and "xml".</dd>

<dt>loglevel</dt>
<dd>How verbose of logging. Default is INFO. Possible values are
SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST.</dd>
Expand Down Expand Up @@ -282,7 +286,7 @@ <h3 id="NotificationListener">NotificationListener</h3>
<dd>(Optional, Default false) Flag to indicate scenario products
should be accepted. Set to &ldquo;true&rdquo; or &ldquo;yes&rdquo; to
enable.</dd>

<dt>includeActuals</dt>
<dd>(Optional, Default true) Flag to indicate actual products
should be accepted. Set to &ldquo;false&rdquo; or &ldquo;no&rdquo; to
Expand Down
38 changes: 32 additions & 6 deletions src/gov/usgs/earthquake/distribution/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Bootstrap
*
*
* $Id: Bootstrap.java 22520 2014-12-30 19:29:45Z jmfee $
* $URL: https://ghttrac.cr.usgs.gov/websvn/ProductDistribution/trunk/src/gov/usgs/earthquake/distribution/Bootstrap.java $
*/
Expand All @@ -20,19 +20,22 @@
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.logging.ConsoleHandler;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.XMLFormatter;

/**
* Bootstrap is a class used to start an application.
*
*
* It loads a configuration file, sets up initial logging, and starts a
* configurable main method.
*
*
* @author jmfee
*
*
*/
public class Bootstrap {

Expand Down Expand Up @@ -60,6 +63,17 @@ public class Bootstrap {
/** Whether to test config only. */
public static final String CONFIG_TEST_ARGUMENT = "--configTest";

/** Property for log format. */
public static final String LOGFORMAT_PROPERTY_NAME = "logformat";
/** log format value for "pdl" format */
public static final String LOGFORMAT_PDL = "pdl";
/** log format value for java "simple" format */
public static final String LOGFORMAT_SIMPLE = "simple";
/** log format value for java "xml" format */
public static final String LOGFORMAT_XML = "xml";
/** Default log format is "simple". */
public static final String DEFAULT_LOGFORMAT = LOGFORMAT_PDL;

/** Property for log level. */
public static final String LOGLEVEL_PROPERTY_NAME = "loglevel";
/** Default log level is "INFO". */
Expand Down Expand Up @@ -107,7 +121,7 @@ public Bootstrap() {

/**
* Read configuration from inside jar file, and configFile.
*
*
* @param configFile
* config file to load.
* @throws IOException
Expand Down Expand Up @@ -183,7 +197,19 @@ public void setupLogging(final Config config) {
rootLogger.addHandler(handler);
}

SimpleLogFormatter formatter = new SimpleLogFormatter();
Formatter formatter;
String logFormat = config.getProperty(
LOGFORMAT_PROPERTY_NAME, DEFAULT_LOGFORMAT);
if (logFormat.equals(LOGFORMAT_SIMPLE)) {
// built in simple formatter
formatter = new SimpleFormatter();
} else if (logFormat.equals(LOGFORMAT_XML)) {
// built in xml formatter
formatter = new XMLFormatter();
} else {
// pdl style simple formatter
formatter = new SimpleLogFormatter();
}
for (Handler handler : rootLogger.getHandlers()) {
handler.setFormatter(formatter);
}
Expand Down

0 comments on commit 4cf227a

Please sign in to comment.