1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
8 *******************************************************************************/
10 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
;
12 import java
.io
.BufferedWriter
;
13 import java
.io
.FileWriter
;
14 import java
.io
.IOException
;
16 import org
.eclipse
.core
.runtime
.Platform
;
19 * Tracer class for the tmf.ui plugin
21 @SuppressWarnings("nls")
22 public class TmfUiTracer
{
24 private static String pluginID
= Activator
.PLUGIN_ID
;
26 static boolean ERROR
= false;
27 static boolean WARNING
= false;
28 static boolean INFO
= false;
30 static boolean INDEX
= false;
31 static boolean DISPLAY
= false;
32 static boolean SORTING
= false;
34 private static String LOGNAME
= "traceUI.log";
35 private static BufferedWriter fTraceLog
= null;
37 private static BufferedWriter
openLogFile(String filename
) {
38 BufferedWriter outfile
= null;
40 outfile
= new BufferedWriter(new FileWriter(filename
));
41 } catch (IOException e
) {
42 Activator
.getDefault().logError("Error creating log file " + LOGNAME
, e
); //$NON-NLS-1$
50 public static void init() {
53 boolean isTracing
= false;
55 traceKey
= Platform
.getDebugOption(pluginID
+ "/error");
56 if (traceKey
!= null) {
57 ERROR
= (Boolean
.valueOf(traceKey
)).booleanValue();
61 traceKey
= Platform
.getDebugOption(pluginID
+ "/warning");
62 if (traceKey
!= null) {
63 WARNING
= (Boolean
.valueOf(traceKey
)).booleanValue();
67 traceKey
= Platform
.getDebugOption(pluginID
+ "/info");
68 if (traceKey
!= null) {
69 INFO
= (Boolean
.valueOf(traceKey
)).booleanValue();
73 traceKey
= Platform
.getDebugOption(pluginID
+ "/updateindex");
74 if (traceKey
!= null) {
75 INDEX
= (Boolean
.valueOf(traceKey
)).booleanValue();
79 traceKey
= Platform
.getDebugOption(pluginID
+ "/display");
80 if (traceKey
!= null) {
81 DISPLAY
= (Boolean
.valueOf(traceKey
)).booleanValue();
85 traceKey
= Platform
.getDebugOption(pluginID
+ "/sorting");
86 if (traceKey
!= null) {
87 SORTING
= (Boolean
.valueOf(traceKey
)).booleanValue();
91 // Create trace log file if needed
93 fTraceLog
= openLogFile(LOGNAME
);
100 public static void stop() {
101 if (fTraceLog
== null) {
108 } catch (IOException e
) {
109 Activator
.getDefault().logError("Error closing log file " + LOGNAME
, e
); //$NON-NLS-1$
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
118 * @return If ERROR messages are traced
120 public static boolean isErrorTraced() {
125 * @return If INDEX messages are traced
127 public static boolean isIndexTraced() {
132 * @return If DISPLAY messages are traced
134 public static boolean isDisplayTraced() {
139 * @return If SORTING messages are traced
141 public static boolean isSortingTraced() {
146 // ------------------------------------------------------------------------
148 // ------------------------------------------------------------------------
151 * Trace a generic event
154 * The event's message
156 public static void trace(String msg
) {
157 // Leave when there is no place to write the message.
158 if (fTraceLog
== null) {
162 long currentTime
= System
.currentTimeMillis();
163 StringBuilder message
= new StringBuilder("[");
164 message
.append(currentTime
/ 1000);
166 message
.append(String
.format("%1$03d", currentTime
% 1000));
167 message
.append("] ");
171 fTraceLog
.write(message
.toString());
174 } catch (IOException e
) {
175 Activator
.getDefault().logError("Error writing to log file " + LOGNAME
, e
); //$NON-NLS-1$
180 * Trace an INDEX event
183 * The event's message
185 public static void traceIndex(String msg
) {
186 String message
= ("[INDEX] " + msg
);
191 * Trace a DISPLAY event
194 * The event's message
196 public static void traceDisplay(String msg
) {
197 String message
= ("[DISPLAY]" + msg
);
202 * Trace a SORTING event
205 * The event's message
207 public static void traceSorting(String msg
) {
208 String message
= ("[SORT] " + msg
);
213 * Trace an ERROR event
216 * The event's message
218 public static void traceError(String msg
) {
219 String message
= ("[ERR] Thread=" + Thread
.currentThread().getId() + " " + msg
);
224 * Trace a WARNING event
227 * The event's message
229 public static void traceWarning(String msg
) {
230 String message
= ("[WARN] Thread=" + Thread
.currentThread().getId() + " " + msg
);
235 * Trace an INFO event
238 * The event's message
240 public static void traceInfo(String msg
) {
241 String message
= ("[INF] Thread=" + Thread
.currentThread().getId() + " " + msg
);
This page took 0.046094 seconds and 5 git commands to generate.