KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > log > LoggerConfig


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.log;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.util.L10N;
34
35 import javax.annotation.PostConstruct;
36 import java.util.logging.Level JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38
39 /**
40  * Environment-specific java.util.logging.Logger configuration.
41  */

42 public class LoggerConfig {
43   private static final L10N L = new L10N(LoggerConfig.class);
44
45   private Logger JavaDoc _logger;
46   private Level JavaDoc _level;
47   private Boolean JavaDoc _useParentHandlers;
48
49   /**
50    * Sets the name of the logger to configure.
51    */

52   public void setName(String JavaDoc name)
53   {
54     _logger = Logger.getLogger(name);
55   }
56
57   /**
58    * Sets the use-parent-handlers
59    */

60   public void setUseParentHandlers(boolean useParentHandlers)
61   {
62     _useParentHandlers = new Boolean JavaDoc(useParentHandlers);
63   }
64   
65   /**
66    * Sets the output level.
67    */

68   public void setLevel(String JavaDoc level)
69     throws ConfigException
70   {
71     if (level.equals("off"))
72       _level = Level.OFF;
73     else if (level.equals("severe"))
74       _level = Level.SEVERE;
75     else if (level.equals("warning"))
76       _level = Level.WARNING;
77     else if (level.equals("info"))
78       _level = Level.INFO;
79     else if (level.equals("config"))
80       _level = Level.CONFIG;
81     else if (level.equals("fine"))
82       _level = Level.FINE;
83     else if (level.equals("finer"))
84       _level = Level.FINER;
85     else if (level.equals("finest"))
86       _level = Level.FINEST;
87     else if (level.equals("all"))
88       _level = Level.ALL;
89     else
90       throw new ConfigException(L.l("`{0}' is an unknown log level. Log levels are:\noff - disable logging\nsevere - severe errors only\nwarning - warnings\ninfo - information\nconfig - configuration\nfine - fine debugging\nfiner - finer debugging\nfinest - finest debugging\nall - all debugging", level));
91   }
92
93   /**
94    * Initialize the logger.
95    */

96   @PostConstruct
97   public void init()
98   {
99     if (_level != null)
100       _logger.setLevel(_level);
101
102     if (_useParentHandlers != null)
103       _logger.setUseParentHandlers(_useParentHandlers.booleanValue());
104   }
105 }
106
Popular Tags