1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statcvs.util;
24
25 import java.util.logging.Level;
26 import java.util.logging.LogRecord;
27 import java.util.logging.StreamHandler;
28
29 /**
30 * A simplified copy of <code>java.util.logging.ConsoleHandler</code>.
31 * It writes to <code>System.out</code> instead of
32 * <code>System.err</code> and uses the {@link LogFormatter}
33 * to format
34 * @author Richard Cyganiak <rcyg@gmx.de>
35 * @version $Id: ConsoleOutHandler.java,v 1.3 2008/04/02 11:22:15 benoitx Exp $
36 */
37 public class ConsoleOutHandler extends StreamHandler {
38
39 /**
40 * Create a <tt>ConsoleOutHandler</tt> for <tt>System.out</tt>.
41 */
42 public ConsoleOutHandler() {
43 setLevel(Level.FINEST);
44 setFormatter(new LogFormatter());
45 setOutputStream(System.out);
46 }
47
48 /**
49 * Publish a <tt>LogRecord</tt>.
50 * <p>
51 * The logging request was made initially to a <tt>Logger</tt> object,
52 * which initialized the <tt>LogRecord</tt> and forwarded it here.
53 * <p>
54 * @param record description of the log event
55 */
56 public void publish(final LogRecord record) {
57 super.publish(record);
58 flush();
59 }
60
61 /**
62 * Override <tt>StreamHandler.close</tt> to do a flush but not
63 * to close the output stream. That is, we do <b>not</b>
64 * close <tt>System.err</tt>.
65 */
66 public void close() {
67 flush();
68 }
69 }