1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
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.
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.
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,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
30
* (C) Copyright 2004, by Object Refinery Limited.
32
* Original Author: Thomas Morgner;
33
* Contributor(s): David Gilbert (for Object Refinery Limited);
35
* $Id: DefaultLog.java,v 1.9 2006/02/19 21:10:48 taqua Exp $
39
* 07-Jun-2004 : Added JCommon header (DG);
43
package org.jfree.base.log;
45
import org.jfree.util.Log;
46
import org.jfree.util.LogTarget;
47
import org.jfree.util.PrintStreamLogTarget;
50
* A default log implementation. The Log class defines how to create Logger-contexts
51
* and how to forward messages to the logtargets.
53
* @author Thomas Morgner
55
public class DefaultLog extends Log {
57
/** The default log target. */
58
private static final PrintStreamLogTarget DEFAULT_LOG_TARGET =
59
new PrintStreamLogTarget();
61
/** The default log instance. */
62
private static final DefaultLog defaultLogInstance;
67
protected DefaultLog () {
72
defaultLogInstance = new DefaultLog();
73
defaultLogInstance.addTarget(DEFAULT_LOG_TARGET);
75
// check the system property. This is the developers backdoor to activate
76
// debug output as soon as possible.
77
final String property = System.getProperty("org.jfree.DebugDefault", "false");
78
if (Boolean.valueOf(property).booleanValue()) {
79
defaultLogInstance.setDebuglevel(LogTarget.DEBUG);
82
defaultLogInstance.setDebuglevel(LogTarget.WARN);
85
catch (SecurityException se) {
86
defaultLogInstance.setDebuglevel(LogTarget.WARN);
91
* Initializes the log system after the log module was loaded and a log target
92
* was defined. This is the second step of the log initialisation.
95
removeTarget(DEFAULT_LOG_TARGET);
96
final String logLevel = LogConfiguration.getLogLevel();
97
if (logLevel.equalsIgnoreCase("error")) {
98
setDebuglevel(LogTarget.ERROR);
100
else if (logLevel.equalsIgnoreCase("warn")) {
101
setDebuglevel(LogTarget.WARN);
103
else if (logLevel.equalsIgnoreCase("info")) {
104
setDebuglevel(LogTarget.INFO);
106
else if (logLevel.equalsIgnoreCase("debug")) {
107
setDebuglevel(LogTarget.DEBUG);
112
* Adds a log target to this facility. Log targets get informed, via the
113
* LogTarget interface, whenever a message is logged with this class.
115
* @param target the target.
117
public synchronized void addTarget(final LogTarget target)
119
super.addTarget(target);
120
// as soon as there is a real log target added, we do no longer need
121
// the default logging. This was only installed to be able to send messages
122
// if the deepest basic logging failed.
123
if (target != DEFAULT_LOG_TARGET) {
124
removeTarget(DEFAULT_LOG_TARGET);
129
* Returns the default log.
131
* @return The default log.
133
public static DefaultLog getDefaultLog() {
134
return defaultLogInstance;
138
* Makes this implementation the default instance.
140
public static void installDefaultLog () {
141
Log.defineLog(defaultLogInstance);