1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
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 }