KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > util > Log


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.intro.impl.util;
12
13 import org.eclipse.core.runtime.ILog;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.MultiStatus;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.ui.internal.intro.impl.IIntroConstants;
19 import org.eclipse.ui.internal.intro.impl.IntroPlugin;
20
21 /**
22  * Utility class for logging, based on Platform logging classes. The log
23  * listerner used is the base one supplied by the platform. Error messages are
24  * always logged. Warning messages are only logged when the plugin is in debug
25  * mode. Info messages are only logged when the /trace/logInfo debug option is
26  * set to true. Performance reports are only logged when /trace/performance is
27  * set to true.
28  *
29  */

30 public class Log implements IIntroConstants {
31
32     /**
33      * This MUST be set to <b>false </b> in production. <br>
34      * Used to compile out developement debug messages. <br>
35      * Compiler compiles out code warpped wit this flag as an optimization.
36      */

37     public static final boolean DEBUG = false;
38
39
40     // Use these flags to filter out code that may be a performance hit.
41
// Flag that controls logging of warning message
42
public static boolean logWarning = false;
43     // Flag that controls logging of information messages
44
public static boolean logInfo = false;
45     // Flag that controls logging of performance messages
46
public static boolean logPerformance = false;
47
48     private final static ILog pluginLog = IntroPlugin.getDefault().getLog();
49
50     static {
51         // init debug options based on settings defined in ".options" file. If
52
// the plugin is not in debug mode, no point setting debug options.
53
if (IntroPlugin.getDefault().isDebugging()) {
54             logWarning = true;
55             logInfo = getDebugOption("/trace/logInfo"); //$NON-NLS-1$
56
logPerformance = getDebugOption("/trace/logPerformance"); //$NON-NLS-1$
57
}
58
59     }
60
61     private static boolean getDebugOption(String JavaDoc option) {
62         return "true".equalsIgnoreCase(//$NON-NLS-1$
63
Platform.getDebugOption(PLUGIN_ID + option));
64     }
65
66     /**
67      * Log an Error message with an exception. Note that the message should
68      * already be localized to proper local. Errors are always logged.
69      */

70     public static synchronized void error(String JavaDoc message, Throwable JavaDoc ex) {
71         if (message == null)
72             message = ""; //$NON-NLS-1$
73
Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK,
74             message, ex);
75         pluginLog.log(errorStatus);
76     }
77
78     /**
79      * Log an Information message. Note that the message should already be
80      * localized to proper local. Info messages are only logged when the
81      * /trace/logInfo debug option is true.
82      */

83     public static synchronized void info(String JavaDoc message) {
84         if (!logInfo)
85             // logging of info messages is not enabled.
86
return;
87
88         if (message == null)
89             message = ""; //$NON-NLS-1$
90
Status infoStatus = new Status(IStatus.INFO, PLUGIN_ID, IStatus.OK,
91             message, null);
92         pluginLog.log(infoStatus);
93     }
94
95     /**
96      * Log an Information message. Note that the message should already be
97      * localized to proper local. These messages are always logged. They are not
98      * controlled by any debug flags. Logging of these messages can be
99      * controlled by the public flags in this class.
100      */

101     public static synchronized void forcedInfo(String JavaDoc message) {
102         if (message == null)
103             message = ""; //$NON-NLS-1$
104
Status infoStatus = new Status(IStatus.INFO, PLUGIN_ID, IStatus.OK,
105             message, null);
106         pluginLog.log(infoStatus);
107     }
108
109
110     /**
111      * Log a Warning message. Note that the message should already be localized
112      * to proper local. Warning messages are only logged when the plugin is in
113      * debug mode.
114      */

115     public static synchronized void warning(String JavaDoc message) {
116         if (!logWarning)
117             // no warning messages (ie: plugin is not in debug mode). Default is
118
// to not log warning messages.
119
return;
120
121         if (message == null)
122             message = ""; //$NON-NLS-1$
123
Status warningStatus = new Status(IStatus.WARNING, PLUGIN_ID,
124             IStatus.OK, message, null);
125         pluginLog.log(warningStatus);
126     }
127
128     /**
129      * Log a development debug message. Debug messages are compiled out.
130      */

131     public static synchronized void debugMessage(String JavaDoc className,
132             String JavaDoc message) {
133         if (DEBUG) {
134             MultiStatus debugStatus = new MultiStatus(PLUGIN_ID, IStatus.OK,
135                 className, null);
136             Status infoStatus = new Status(IStatus.OK, PLUGIN_ID, IStatus.OK,
137                 message, null);
138             debugStatus.add(infoStatus);
139             pluginLog.log(debugStatus);
140         }
141     }
142 }
143
Popular Tags