KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > base > log > LogConfiguration


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------------
28  * LogConfiguration.java
29  * ---------------------
30  * (C) Copyright 2004, by Object Refinery Limited.
31  *
32  * Original Author: Thomas Morgner;
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: LogConfiguration.java,v 1.6 2005/12/18 23:29:18 taqua Exp $
36  *
37  * Changes
38  * -------
39  * 07-Jun-2004 : Added JCommon header (DG);
40  *
41  */

42
43 package org.jfree.base.log;
44
45 import org.jfree.base.BaseBoot;
46 import org.jfree.util.PrintStreamLogTarget;
47
48 /**
49  * A log configuration class. This implementation is a simple frontend
50  * to the global configuration.
51  *
52  * @author Thomas Morgner
53  */

54 public class LogConfiguration {
55   /** The default 'disable logging' property value. */
56   public static final String JavaDoc DISABLE_LOGGING_DEFAULT = "false";
57
58   /** The 'log level' property key. */
59   public static final String JavaDoc LOGLEVEL = "org.jfree.base.LogLevel";
60
61   /** The default 'log level' property value. */
62   public static final String JavaDoc LOGLEVEL_DEFAULT = "Info";
63
64   /** The 'log target' property key. */
65   public static final String JavaDoc LOGTARGET = "org.jfree.base.LogTarget";
66
67   /** The default 'log target' property value. */
68   public static final String JavaDoc LOGTARGET_DEFAULT =
69           PrintStreamLogTarget.class.getName();
70
71   /** The 'disable logging' property key. */
72   public static final String JavaDoc DISABLE_LOGGING = "org.jfree.base.NoDefaultDebug";
73
74   /**
75    * Default constructor.
76    */

77   private LogConfiguration() {
78       // nothing required.
79
}
80
81   /**
82    * Returns the current log target.
83    *
84    * @return the log target.
85    */

86   public static String JavaDoc getLogTarget()
87   {
88     return BaseBoot.getInstance().getGlobalConfig().getConfigProperty
89             (LOGTARGET, LOGTARGET_DEFAULT);
90   }
91
92   /**
93    * Sets the log target.
94    *
95    * @param logTarget the new log target.
96    */

97   public static void setLogTarget(final String JavaDoc logTarget)
98   {
99       BaseBoot.getConfiguration().setConfigProperty (LOGTARGET, logTarget);
100   }
101
102   /**
103    * Returns the log level.
104    *
105    * @return the log level.
106    */

107   public static String JavaDoc getLogLevel()
108   {
109     return BaseBoot.getInstance().getGlobalConfig().getConfigProperty
110             (LOGLEVEL, LOGLEVEL_DEFAULT);
111   }
112
113   /**
114    * Sets the log level, which is read from the global report configuration at
115    * the point that the classloader loads the {@link org.jfree.util.Log} class.
116    * <p>
117    * Valid log levels are:
118    *
119    * <ul>
120    * <li><code>"Error"</code> - error messages;</li>
121    * <li><code>"Warn"</code> - warning messages;</li>
122    * <li><code>"Info"</code> - information messages;</li>
123    * <li><code>"Debug"</code> - debug messages;</li>
124    * </ul>
125    *
126    * Notes:
127    * <ul>
128    * <li>the setting is not case sensitive.</li>
129    * <li>changing the log level after the {@link org.jfree.util.Log} class has been
130    * loaded will have no effect.</li>
131    * <li>to turn of logging altogether, use the {@link #setDisableLogging} method.</li>
132    * </ul>
133    *
134    * @param level the new log level.
135    */

136   public static void setLogLevel(final String JavaDoc level)
137   {
138     BaseBoot.getConfiguration().setConfigProperty(LOGLEVEL, level);
139   }
140
141   /**
142    * Returns <code>true</code> if logging is disabled, and <code>false</code> otherwise.
143    *
144    * @return true, if logging is completly disabled, false otherwise.
145    */

146   public static boolean isDisableLogging()
147   {
148     return BaseBoot.getInstance().getGlobalConfig().getConfigProperty
149         (DISABLE_LOGGING, DISABLE_LOGGING_DEFAULT).equalsIgnoreCase("true");
150   }
151
152   /**
153    * Sets the flag that disables logging.
154    * <p>
155    * To switch off logging globally, you can use the following code:
156    * <p>
157    * <code>ReportConfiguration.getGlobalConfig().setDisableLogging(true);</code>
158    *
159    * @param disableLogging the flag.
160    */

161   public static void setDisableLogging(final boolean disableLogging)
162   {
163     BaseBoot.getConfiguration().setConfigProperty
164             (DISABLE_LOGGING, String.valueOf(disableLogging));
165   }
166
167
168 }
169
Popular Tags