01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: RawFormatter.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.tools;
09:
10: import java.io.PrintWriter;
11: import java.io.StringWriter;
12: import java.util.logging.Formatter;
13: import java.util.logging.LogRecord;
14:
15: public class RawFormatter extends Formatter {
16: // Line separator string. This is the value of the line.separator
17: // property at the moment that the SimpleFormatter was created.
18: private String lineSeparator = (String) java.security.AccessController
19: .doPrivileged(new java.security.PrivilegedAction() {
20: public Object run() {
21: return System.getProperty("line.separator");
22: }
23: });
24:
25: /**
26: * Format the given LogRecord.
27: * @param record the log record to be formatted.
28: * @return a formatted log record
29: */
30: public synchronized String format(LogRecord record) {
31: StringBuilder sb = new StringBuilder();
32: String message = formatMessage(record);
33: sb.append(message);
34: sb.append(lineSeparator);
35: if (record.getThrown() != null) {
36: try {
37: StringWriter sw = new StringWriter();
38: PrintWriter pw = new PrintWriter(sw);
39: record.getThrown().printStackTrace(pw);
40: pw.close();
41: sb.append(sw.toString());
42: } catch (Exception ex) {
43: }
44: }
45: return sb.toString();
46: }
47: }
|