View Javadoc

1   /* ======================================
2    * Copyright (c) 2004-2005 Achim Nierbeck
3    * All rights reserved.
4    *
5    * You may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.gnu.org/licenses/lgpl.html
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   * ======================================
16   */
17  
18  /*
19   * TimeTrackLog.java
20   * $Revision: 1.2 $
21   * Date 14.12.2005
22   * 
23   * $Author: nierbeck $ 
24   * $Date: 2006/02/02 21:27:59 $  
25   */
26  
27  package de.nierbeck.timeTrack;
28  
29  import org.eclipse.core.runtime.IStatus;
30  import org.eclipse.core.runtime.Status;
31  
32  /***
33   * The logger of convenience for the TimeTrack plug-in. taken from the example
34   * given by "how to build comercial grade plugins"
35   */
36  public final class TimeTrackLog {
37  	
38  	private TimeTrackLog() {
39  		//private Constructor for disguise
40  	}
41  
42  	/***
43  	 * Log the specified information.
44  	 * 
45  	 * @param message
46  	 *            a human-readable message, localized to the current locale
47  	 */
48  	public static void logInfo(String message) {
49  		log(IStatus.INFO, IStatus.OK, message, null);
50  	}
51  
52  	/***
53  	 * Log the specified error. 3.6. Logging 37
54  	 * 
55  	 * @param exception
56  	 *            a low-level exception
57  	 */
58  	public static void logError(Throwable exception) {
59  		logError("Unexpected Exception", exception);
60  	}
61  
62  	/***
63  	 * Log the specified error.
64  	 * 
65  	 * @param message
66  	 *            a human-readable message, localized to the current locale
67  	 * @param exception
68  	 *            a low-level exception, or <code>null</code> if not
69  	 *            applicable
70  	 */
71  	public static void logError(String message, Throwable exception) {
72  		log(IStatus.ERROR, IStatus.OK, message, exception);
73  	}
74  
75  	/***
76  	 * Log the specified information.
77  	 * 
78  	 * @param severity
79  	 *            the severity; one of <code>IStatus.OK</code>,
80  	 *            <code>IStatus.ERROR</code>, <code>IStatus.INFO</code>,
81  	 *            or <code>IStatus.WARNING</code>
82  	 * @param code - the plug-in-specific status code, or <code>OK</code>
83  	 * @param message - a human-readable message, localized to the current locale
84  	 * @param exception - a low-level exception, or <code>null</code> if not applicable
85  	 */
86  	public static void log(int severity, int code, String message,
87  			Throwable exception) {
88  		log(createStatus(severity, code, message, exception));
89  	}
90  
91  	/***
92  	 * Create a status object representing the specified information. 38
93  	 * TChapterT 3 Eclipse Infrastructure
94  	 * 
95  	 * @param severity - 
96  	 *            the severity; one of <code>IStatus.OK</code>,
97  	 *            <code>IStatus.ERROR</code>, <code>IStatus.INFO</code>,
98  	 *            or <code>IStatus.WARNING</code>
99  	 * @param code
100 	 *            the plug-in-specific status code, or <code>OK</code>
101 	 * @param message
102 	 *            a human-readable message, localized to the current locale
103 	 * @param exception
104 	 *            a low-level exception, or <code>null</code> if not
105 	 *            applicable
106 	 * @return the status object (not <code>null</code>)
107 	 */
108 	public static IStatus createStatus(int severity, int code, String message,
109 			Throwable exception) {
110 		return new Status(severity, TimeTrackPlugin.getDefault().getBundle()
111 				.getSymbolicName(), code, message, exception);
112 	}
113 
114 	/***
115 	 * Log the given status.
116 	 * 
117 	 * @param status
118 	 *            the status to log
119 	 */
120 	public static void log(IStatus status) {
121 		TimeTrackPlugin.getDefault().getLog().log(status);
122 	}
123 }