Author: [log in to unmask]
Date: Mon Apr 27 16:06:56 2015
New Revision: 3596
Log:
Add a log formatter that will print only the message and tracebacks.
Added:
projects/lcsim/trunk/util/src/main/java/org/lcsim/util/log/MessageOnlyLogFormatter.java
Added: projects/lcsim/trunk/util/src/main/java/org/lcsim/util/log/MessageOnlyLogFormatter.java
=============================================================================
--- projects/lcsim/trunk/util/src/main/java/org/lcsim/util/log/MessageOnlyLogFormatter.java (added)
+++ projects/lcsim/trunk/util/src/main/java/org/lcsim/util/log/MessageOnlyLogFormatter.java Mon Apr 27 16:06:56 2015
@@ -0,0 +1,46 @@
+package org.lcsim.util.log;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+/**
+ * A log <code>Formatter</code> that prints only the message and error tracebacks.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class MessageOnlyLogFormatter extends Formatter {
+
+ /**
+ * Class constructor.
+ */
+ public MessageOnlyLogFormatter() {
+ }
+
+ /**
+ * Format the <code>LogRecord</code> for printing
+ *
+ * @param record the <code>LogRecord</code> to format
+ */
+ @Override
+ public String format(final LogRecord record) {
+ final StringBuilder sb = new StringBuilder();
+
+ // Append the message.
+ sb.append(formatMessage(record) + '\n');
+
+ // Append a traceback if there was an error thrown.
+ if (record.getThrown() != null) {
+ try {
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ record.getThrown().printStackTrace(pw);
+ pw.close();
+ sb.append(sw.toString());
+ } catch (final Exception ex) {
+ }
+ }
+ return sb.toString();
+ }
+}
########################################################################
Use REPLY-ALL to reply to list
To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1
|