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.ConsoleHandler;
26 import java.util.logging.Handler;
27 import java.util.logging.Level;
28 import java.util.logging.LogRecord;
29
30 /**
31 * Customized console logging handler.
32 * <p>
33 * The <tt>ConsoleOutErrHandler</tt> writes log messages
34 * of severity <tt>WARNING</tt> and higher to the <tt>System.err</tt>
35 * stream, and all other log messages to <tt>System.out</tt>.
36 * It uses a {@link LogFormatter} to format the records.
37 *
38 * @author Richard Cyganiak <rcyg@gmx.de>
39 * @version $Id: ConsoleOutErrHandler.java,v 1.3 2008/04/02 11:22:15 benoitx Exp $
40 */
41 public class ConsoleOutErrHandler extends Handler {
42
43 private final Handler errHandler = new ConsoleHandler();
44 private final Handler outHandler = new ConsoleOutHandler();
45
46 /**
47 * Constructor for ConsoleOutErrHandler.
48 */
49 public ConsoleOutErrHandler() {
50 super();
51 }
52
53 /**
54 * @see java.util.logging.Handler#publish(LogRecord)
55 * @param record a log record
56 */
57 public void publish(final LogRecord record) {
58 if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
59 errHandler.publish(record);
60 } else {
61 outHandler.publish(record);
62 }
63 }
64
65 /**
66 * @see java.util.logging.Handler#flush()
67 */
68 public void flush() {
69 errHandler.flush();
70 outHandler.flush();
71 }
72
73 /**
74 * @see java.util.logging.Handler#close()
75 */
76 public void close() throws SecurityException {
77 errHandler.close();
78 outHandler.close();
79 }
80 }