View Javadoc

1   /*
2       StatCvs - CVS statistics generation 
3       Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4       http://statcvs.sf.net/
5       
6       This library is free software; you can redistribute it and/or
7       modify it under the terms of the GNU Lesser General Public
8       License as published by the Free Software Foundation; either
9       version 2.1 of the License, or (at your option) any later version.
10  
11      This library is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14      Lesser General Public License for more details.
15  
16      You should have received a copy of the GNU Lesser General Public
17      License along with this library; if not, write to the Free Software
18      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19      
20  	$RCSfile: ConsoleOutErrHandler.java,v $
21  	Created on $Date: 2008/04/02 11:22:15 $ 
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  }