001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ---------------------
028: * LogConfiguration.java
029: * ---------------------
030: * (C) Copyright 2004, by Object Refinery Limited.
031: *
032: * Original Author: Thomas Morgner;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: LogConfiguration.java,v 1.6 2005/12/18 23:29:18 taqua Exp $
036: *
037: * Changes
038: * -------
039: * 07-Jun-2004 : Added JCommon header (DG);
040: *
041: */
042:
043: package org.jfree.base.log;
044:
045: import org.jfree.base.BaseBoot;
046: import org.jfree.util.PrintStreamLogTarget;
047:
048: /**
049: * A log configuration class. This implementation is a simple frontend
050: * to the global configuration.
051: *
052: * @author Thomas Morgner
053: */
054: public class LogConfiguration {
055: /** The default 'disable logging' property value. */
056: public static final String DISABLE_LOGGING_DEFAULT = "false";
057:
058: /** The 'log level' property key. */
059: public static final String LOGLEVEL = "org.jfree.base.LogLevel";
060:
061: /** The default 'log level' property value. */
062: public static final String LOGLEVEL_DEFAULT = "Info";
063:
064: /** The 'log target' property key. */
065: public static final String LOGTARGET = "org.jfree.base.LogTarget";
066:
067: /** The default 'log target' property value. */
068: public static final String LOGTARGET_DEFAULT = PrintStreamLogTarget.class
069: .getName();
070:
071: /** The 'disable logging' property key. */
072: public static final String DISABLE_LOGGING = "org.jfree.base.NoDefaultDebug";
073:
074: /**
075: * Default constructor.
076: */
077: private LogConfiguration() {
078: // nothing required.
079: }
080:
081: /**
082: * Returns the current log target.
083: *
084: * @return the log target.
085: */
086: public static String getLogTarget() {
087: return BaseBoot.getInstance().getGlobalConfig()
088: .getConfigProperty(LOGTARGET, LOGTARGET_DEFAULT);
089: }
090:
091: /**
092: * Sets the log target.
093: *
094: * @param logTarget the new log target.
095: */
096: public static void setLogTarget(final String logTarget) {
097: BaseBoot.getConfiguration().setConfigProperty(LOGTARGET,
098: logTarget);
099: }
100:
101: /**
102: * Returns the log level.
103: *
104: * @return the log level.
105: */
106: public static String getLogLevel() {
107: return BaseBoot.getInstance().getGlobalConfig()
108: .getConfigProperty(LOGLEVEL, LOGLEVEL_DEFAULT);
109: }
110:
111: /**
112: * Sets the log level, which is read from the global report configuration at
113: * the point that the classloader loads the {@link org.jfree.util.Log} class.
114: * <p>
115: * Valid log levels are:
116: *
117: * <ul>
118: * <li><code>"Error"</code> - error messages;</li>
119: * <li><code>"Warn"</code> - warning messages;</li>
120: * <li><code>"Info"</code> - information messages;</li>
121: * <li><code>"Debug"</code> - debug messages;</li>
122: * </ul>
123: *
124: * Notes:
125: * <ul>
126: * <li>the setting is not case sensitive.</li>
127: * <li>changing the log level after the {@link org.jfree.util.Log} class has been
128: * loaded will have no effect.</li>
129: * <li>to turn of logging altogether, use the {@link #setDisableLogging} method.</li>
130: * </ul>
131: *
132: * @param level the new log level.
133: */
134: public static void setLogLevel(final String level) {
135: BaseBoot.getConfiguration().setConfigProperty(LOGLEVEL, level);
136: }
137:
138: /**
139: * Returns <code>true</code> if logging is disabled, and <code>false</code> otherwise.
140: *
141: * @return true, if logging is completly disabled, false otherwise.
142: */
143: public static boolean isDisableLogging() {
144: return BaseBoot.getInstance().getGlobalConfig()
145: .getConfigProperty(DISABLE_LOGGING,
146: DISABLE_LOGGING_DEFAULT).equalsIgnoreCase(
147: "true");
148: }
149:
150: /**
151: * Sets the flag that disables logging.
152: * <p>
153: * To switch off logging globally, you can use the following code:
154: * <p>
155: * <code>ReportConfiguration.getGlobalConfig().setDisableLogging(true);</code>
156: *
157: * @param disableLogging the flag.
158: */
159: public static void setDisableLogging(final boolean disableLogging) {
160: BaseBoot.getConfiguration().setConfigProperty(DISABLE_LOGGING,
161: String.valueOf(disableLogging));
162: }
163:
164: }
|