1 package org
.eclipse
.linuxtools
.internal
.tmf
.core
;
3 import java
.io
.BufferedWriter
;
4 import java
.io
.FileWriter
;
5 import java
.io
.IOException
;
6 import java
.io
.OutputStreamWriter
;
8 import org
.eclipse
.core
.runtime
.Platform
;
9 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfComponent
;
10 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
11 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
12 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
13 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignal
;
15 @SuppressWarnings({"nls", "javadoc"})
18 private static String pluginID
= Activator
.PLUGIN_ID
;
20 static Boolean ERROR
= Boolean
.FALSE
;
21 static Boolean WARNING
= Boolean
.FALSE
;
22 static Boolean INFO
= Boolean
.FALSE
;
24 static Boolean COMPONENT
= Boolean
.FALSE
;
25 static Boolean REQUEST
= Boolean
.FALSE
;
26 static Boolean SIGNAL
= Boolean
.FALSE
;
27 static Boolean EVENT
= Boolean
.FALSE
;
29 private static String LOGNAME
= "trace.log";
30 private static BufferedWriter fTraceLog
= new BufferedWriter(new OutputStreamWriter(System
.out
));
32 private static BufferedWriter
openLogFile(String filename
) {
33 BufferedWriter outfile
= null;
35 outfile
= new BufferedWriter(new FileWriter(filename
));
36 } catch (IOException e
) {
37 Activator
.getDefault().logError("Error opening log file " + filename
, e
);
42 public static void init() {
45 boolean isTracing
= false;
47 traceKey
= Platform
.getDebugOption(pluginID
+ "/error");
48 if (traceKey
!= null) {
49 ERROR
= (Boolean
.valueOf(traceKey
)).booleanValue();
53 traceKey
= Platform
.getDebugOption(pluginID
+ "/warning");
54 if (traceKey
!= null) {
55 WARNING
= (Boolean
.valueOf(traceKey
)).booleanValue();
59 traceKey
= Platform
.getDebugOption(pluginID
+ "/info");
60 if (traceKey
!= null) {
61 INFO
= (Boolean
.valueOf(traceKey
)).booleanValue();
65 traceKey
= Platform
.getDebugOption(pluginID
+ "/component");
66 if (traceKey
!= null) {
67 COMPONENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
68 isTracing
|= COMPONENT
;
71 traceKey
= Platform
.getDebugOption(pluginID
+ "/request");
72 if (traceKey
!= null) {
73 REQUEST
= (Boolean
.valueOf(traceKey
)).booleanValue();
77 traceKey
= Platform
.getDebugOption(pluginID
+ "/signal");
78 if (traceKey
!= null) {
79 SIGNAL
= (Boolean
.valueOf(traceKey
)).booleanValue();
83 traceKey
= Platform
.getDebugOption(pluginID
+ "/event");
84 if (traceKey
!= null) {
85 EVENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
89 // Create trace log file if needed
91 fTraceLog
= openLogFile(LOGNAME
);
95 public static void stop() {
96 if (fTraceLog
== null) {
103 } catch (IOException e
) {
104 Activator
.getDefault().logError("Error closing log file", e
);
109 public static boolean isErrorTraced() {
113 public static boolean isComponentTraced() {
117 public static boolean isRequestTraced() {
121 public static boolean isSignalTraced() {
125 public static boolean isEventTraced() {
130 public static synchronized void trace(String msg
) {
131 long currentTime
= System
.currentTimeMillis();
132 StringBuilder message
= new StringBuilder("[");
133 message
.append(currentTime
/ 1000);
135 message
.append(String
.format("%1$03d", currentTime
% 1000));
136 message
.append("] ");
138 message
.append("[Th=");
139 message
.append(String
.format("%1$03d", Thread
.currentThread().getId()));
140 message
.append("] ");
144 if (fTraceLog
!= null) {
146 fTraceLog
.write(message
.toString());
149 } catch (IOException e
) {
150 Activator
.getDefault().logError("Error writing to log file", e
);
155 public static void traceComponent(ITmfComponent component
, String msg
) {
156 String message
= ("[CMP] Cmp=" + component
.getName() + " " + msg
);
160 public static void traceRequest(ITmfDataRequest
<?
> request
, String msg
) {
161 String message
= ("[REQ] Req=" + request
.getRequestId() + " " + msg
);
165 public static void traceSignal(TmfSignal signal
, String msg
) {
166 String message
= ("[SIG] Sig=" + signal
.getClass().getSimpleName() + " Target=" + msg
);
170 public static void traceEvent(ITmfDataProvider
<?
> provider
, ITmfDataRequest
<?
> request
, ITmfEvent event
) {
171 String message
= ("[EVT] Provider=" + provider
.toString() + ", Req=" + request
.getRequestId() + ", Event=" + event
.getTimestamp());
175 public static void traceError(String msg
) {
176 String message
= ("[ERR] Err=" + msg
);
180 public static void traceInfo(String msg
) {
181 String message
= ("[INF] " + msg
);
This page took 0.033708 seconds and 5 git commands to generate.