Fix for bug 357525 (fix for endless loop)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / TmfUiTracer.java
1 package org.eclipse.linuxtools.tmf.ui;
2
3 import java.io.BufferedWriter;
4 import java.io.FileWriter;
5 import java.io.IOException;
6
7 import org.eclipse.core.runtime.Platform;
8
9 @SuppressWarnings("nls")
10 public class TmfUiTracer {
11
12 private static String pluginID = TmfUiPlugin.PLUGIN_ID;
13
14 static Boolean ERROR = Boolean.FALSE;
15 static Boolean WARNING = Boolean.FALSE;
16 static Boolean INFO = Boolean.FALSE;
17
18 static Boolean INDEX = Boolean.FALSE;
19 static Boolean DISPLAY = Boolean.FALSE;
20 static Boolean SORTING = Boolean.FALSE;
21
22 private static String LOGNAME = "traceUI.log";
23 private static BufferedWriter fTraceLog = null;
24
25 private static BufferedWriter openLogFile(String filename) {
26 BufferedWriter outfile = null;
27 try {
28 outfile = new BufferedWriter(new FileWriter(filename));
29 } catch (IOException e) {
30 e.printStackTrace();
31 }
32 return outfile;
33 }
34
35 public static void init() {
36
37 String traceKey;
38 boolean isTracing = false;
39
40 traceKey = Platform.getDebugOption(pluginID + "/error");
41 if (traceKey != null) {
42 ERROR = (Boolean.valueOf(traceKey)).booleanValue();
43 isTracing |= ERROR;
44 }
45
46 traceKey = Platform.getDebugOption(pluginID + "/warning");
47 if (traceKey != null) {
48 WARNING = (Boolean.valueOf(traceKey)).booleanValue();
49 isTracing |= WARNING;
50 }
51
52 traceKey = Platform.getDebugOption(pluginID + "/info");
53 if (traceKey != null) {
54 INFO = (Boolean.valueOf(traceKey)).booleanValue();
55 isTracing |= INFO;
56 }
57
58 traceKey = Platform.getDebugOption(pluginID + "/updateindex");
59 if (traceKey != null) {
60 INDEX = (Boolean.valueOf(traceKey)).booleanValue();
61 isTracing |= INDEX;
62 }
63
64 traceKey = Platform.getDebugOption(pluginID + "/display");
65 if (traceKey != null) {
66 DISPLAY = (Boolean.valueOf(traceKey)).booleanValue();
67 isTracing |= DISPLAY;
68 }
69
70 traceKey = Platform.getDebugOption(pluginID + "/sorting");
71 if (traceKey != null) {
72 SORTING = (Boolean.valueOf(traceKey)).booleanValue();
73 isTracing |= SORTING;
74 }
75
76 // Create trace log file if needed
77 if (isTracing) {
78 fTraceLog = openLogFile(LOGNAME);
79 }
80 }
81
82 public static void stop() {
83 if (fTraceLog == null)
84 return;
85
86 try {
87 fTraceLog.close();
88 fTraceLog = null;
89 } catch (IOException e) {
90 e.printStackTrace();
91 }
92 }
93
94 // Predicates
95 public static boolean isErrorTraced() {
96 return ERROR;
97 }
98
99 public static boolean isIndexTraced() {
100 return INDEX;
101 }
102
103 public static boolean isDisplayTraced() {
104 return DISPLAY;
105 }
106
107 public static boolean isSortingTraced() {
108 return SORTING;
109 }
110
111 // Tracers
112 public static void trace(String msg) {
113 long currentTime = System.currentTimeMillis();
114 StringBuilder message = new StringBuilder("[");
115 message.append(currentTime / 1000);
116 message.append(".");
117 message.append(String.format("%1$03d", currentTime % 1000));
118 message.append("] ");
119 message.append(msg);
120
121 if (fTraceLog != null) {
122 try {
123 fTraceLog.write(message.toString());
124 fTraceLog.newLine();
125 fTraceLog.flush();
126 } catch (IOException e) {
127 e.printStackTrace();
128 }
129 }
130 }
131
132 public static void traceIndex(String msg) {
133 String message = ("[INDEX] " + msg);
134 trace(message);
135 }
136
137 public static void traceDisplay(String msg) {
138 String message = ("[DISPLAY]" + msg);
139 trace(message);
140 }
141
142 public static void traceSorting(String msg) {
143 String message = ("[SORT] " + msg);
144 trace(message);
145 }
146
147 public static void traceError(String msg) {
148 String message = ("[ERR] Thread=" + Thread.currentThread().getId() + " " + msg);
149 trace(message);
150 }
151
152 public static void traceWarning(String msg) {
153 String message = ("[WARN] Thread=" + Thread.currentThread().getId() + " " + msg);
154 trace(message);
155 }
156
157 public static void traceInfo(String msg) {
158 String message = ("[INF] Thread=" + Thread.currentThread().getId() + " " + msg);
159 trace(message);
160 }
161
162
163
164 }
This page took 0.034531 seconds and 5 git commands to generate.