LISTSERV mailing list manager LISTSERV 16.5

Help for LCDET-SVN Archives


LCDET-SVN Archives

LCDET-SVN Archives


LCDET-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

LCDET-SVN Home

LCDET-SVN Home

LCDET-SVN  April 2015

LCDET-SVN April 2015

Subject:

r3596 - /projects/lcsim/trunk/util/src/main/java/org/lcsim/util/log/MessageOnlyLogFormatter.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the lcdet svn repository <[log in to unmask]>

Date:

Mon, 27 Apr 2015 23:07:04 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (68 lines)

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

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use