01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.util;
04:
05: import java.io.PrintWriter;
06: import java.io.StringWriter;
07: import java.util.logging.Handler;
08: import java.util.logging.LogRecord;
09:
10: /**
11: * Log to the console without using a formatter.
12: *
13: * @author Wouter Zelle
14: */
15: public class ConsoleLogHandler extends Handler {
16:
17: public void publish(LogRecord logRecord) {
18: System.out.println(logRecord.getMessage());
19: if (logRecord.getThrown() != null) {
20: // Use the same channel, to make sure that the stacktrace comes
21: // after the message on the console (using printStackTrace
22: // directly messes things up)
23: StringWriter stringWriter = new StringWriter();
24: PrintWriter printWriter = new PrintWriter(stringWriter,
25: true);
26: logRecord.getThrown().printStackTrace(printWriter);
27: System.out.println(stringWriter.toString());
28: }
29: }
30:
31: public void close() throws SecurityException {
32: return;
33: }
34:
35: public void flush() {
36: return;
37: }
38: }
|