1   /* $RCSfile: LoggerUtil.java,v $
2    * $Revision: 1.2 $
3    * $Date: 2002/11/23 11:09:57 $
4    * $Author: uwe_guenther $
5    * $State: Exp $
6    *
7    * Created on January 11, 2002 10:23 AM
8    *
9    * Copyright (C) 2001 Uwe Guenther <uwe@cscc.de>
10   *
11   * This file is part of the jhbci JCE-ServiceProvider. The jhbci JCE-
12   * ServiceProvider is a library, written in JavaTM, that should be 
13   * used in HBCI banking applications (clients and may be servers),
14   * to do cryptographic operations.
15   *
16   * The jhbci library is free software; you can redistribute it and/or
17   * modify it under the terms of the GNU Lesser General Public
18   * License as published by the Free Software Foundation; either
19   * version 2.1 of the License, or (at your option) any later version.
20   *
21   * The jhbci library is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24   * Lesser General Public License for more details.
25   *
26   * You should have received a copy of the GNU Lesser General Public
27   * License along with this library; if not, write to the Free Software
28   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29   *
30   */
31  
32  package de.cscc.crypto.util;
33  
34  import java.util.logging.ConsoleHandler;
35  import java.util.logging.Handler;
36  import java.util.logging.Level;
37  import java.util.logging.Logger;
38  
39  /** 
40   * LoggerUtil Class.
41   *
42   * @author  <a href=mailto:uwe@cscc.de>Uwe G&uuml;nther</a>
43   *
44   * @version $Revision: 1.2 $
45   */
46  public class LoggerUtil {
47  
48      /** Don't create new LoggerUtil, because its a wrapper for static methods.*/
49      private LoggerUtil() {
50      }
51  
52      public static Logger setConsoleLogging(String category, Level level) {
53          if (category == null) {
54              throw new NullPointerException("Parameter category is null.");
55          }
56          if (level == null) {
57              throw new NullPointerException("Parameter level is null.");
58          }
59          
60          //Switch _all_ global Handlers off.
61          Handler[] handlers = Logger.getLogger("").getHandlers();
62          for(int i = 0; i < handlers.length; i++) {
63              handlers[i].setLevel(Level.OFF);
64          }       
65          
66          //Setup the Logger for 'category'.
67          Logger log = Logger.getLogger(category);
68          
69          //Set the logger to the Level 'level'.
70          log.setLevel(level);
71          
72          //Create and add the ConsoleHandler.
73          Handler consoleHandler = new ConsoleHandler();
74          consoleHandler.setLevel(level);
75          log.addHandler(consoleHandler);     
76          
77          return log;
78      }    
79  }
80