tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / TmfUiTracer.java
index 35ab206ef507e42d6af8d0f904e63bb50ff0582a..8ed4889979489f80e4182c8c8e3a442bab94c6c8 100644 (file)
-package org.eclipse.linuxtools.internal.tmf.ui;\r
-\r
-import java.io.BufferedWriter;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-\r
-import org.eclipse.core.runtime.Platform;\r
-\r
-@SuppressWarnings("nls")\r
-public class TmfUiTracer {\r
-\r
-       private static String pluginID = Activator.PLUGIN_ID;\r
-\r
-       static Boolean ERROR     = Boolean.FALSE;\r
-       static Boolean WARNING   = Boolean.FALSE;\r
-       static Boolean INFO      = Boolean.FALSE;\r
-\r
-       static Boolean INDEX         = Boolean.FALSE;\r
-       static Boolean DISPLAY       = Boolean.FALSE;\r
-       static Boolean SORTING       = Boolean.FALSE;\r
-\r
-       private static String LOGNAME = "traceUI.log";\r
-       private static BufferedWriter fTraceLog = null;\r
-\r
-       private static BufferedWriter openLogFile(String filename) {\r
-               BufferedWriter outfile = null;\r
-               try {\r
-                       outfile = new BufferedWriter(new FileWriter(filename));\r
-               } catch (IOException e) {\r
-                   Activator.getDefault().logError("Error creating log file " + LOGNAME, e); //$NON-NLS-1$\r
-               }\r
-               return outfile;\r
-       }\r
-\r
-       public static void init() {\r
-\r
-               String traceKey;\r
-               boolean isTracing = false;\r
-               \r
-               traceKey = Platform.getDebugOption(pluginID + "/error");\r
-               if (traceKey != null) {\r
-                       ERROR = (Boolean.valueOf(traceKey)).booleanValue();\r
-                       isTracing |= ERROR;\r
-               }\r
-\r
-               traceKey = Platform.getDebugOption(pluginID + "/warning");\r
-               if (traceKey != null) {\r
-                       WARNING = (Boolean.valueOf(traceKey)).booleanValue();\r
-                       isTracing |= WARNING;\r
-               }\r
-\r
-               traceKey = Platform.getDebugOption(pluginID + "/info");\r
-               if (traceKey != null) {\r
-                       INFO = (Boolean.valueOf(traceKey)).booleanValue();\r
-                       isTracing |= INFO;\r
-               }\r
-\r
-               traceKey = Platform.getDebugOption(pluginID + "/updateindex");\r
-               if (traceKey != null) {\r
-                   INDEX = (Boolean.valueOf(traceKey)).booleanValue();\r
-                       isTracing |= INDEX;\r
-               }\r
-\r
-               traceKey = Platform.getDebugOption(pluginID + "/display");\r
-               if (traceKey != null) {\r
-                   DISPLAY = (Boolean.valueOf(traceKey)).booleanValue();\r
-                       isTracing |= DISPLAY;\r
-               }\r
-\r
-               traceKey = Platform.getDebugOption(pluginID + "/sorting");\r
-               if (traceKey != null) {\r
-                   SORTING = (Boolean.valueOf(traceKey)).booleanValue();\r
-                       isTracing |= SORTING;\r
-               }\r
-\r
-               // Create trace log file if needed\r
-               if (isTracing) {\r
-                       fTraceLog = openLogFile(LOGNAME);\r
-               }\r
-       }\r
-\r
-       public static void stop() {\r
-               if (fTraceLog == null)\r
-                       return;\r
-\r
-               try {\r
-                       fTraceLog.close();\r
-                       fTraceLog = null;\r
-               } catch (IOException e) {\r
-                 Activator.getDefault().logError("Error closing log file " + LOGNAME, e); //$NON-NLS-1$\r
-               }\r
-       }\r
-\r
-       // Predicates\r
-       public static boolean isErrorTraced() {\r
-               return ERROR;\r
-       }\r
-\r
-       public static boolean isIndexTraced() {\r
-               return INDEX;\r
-       }\r
-       \r
-       public static boolean isDisplayTraced() {\r
-               return DISPLAY;\r
-       }\r
-       \r
-       public static boolean isSortingTraced() {\r
-               return SORTING;\r
-       }\r
-\r
-       // Tracers\r
-       public static void trace(String msg) {\r
-               long currentTime = System.currentTimeMillis();\r
-               StringBuilder message = new StringBuilder("[");\r
-               message.append(currentTime / 1000);\r
-               message.append(".");\r
-               message.append(String.format("%1$03d", currentTime % 1000));\r
-               message.append("] ");\r
-               message.append(msg);\r
-\r
-               if (fTraceLog != null) {\r
-                       try {\r
-                               fTraceLog.write(message.toString());\r
-                               fTraceLog.newLine();\r
-                               fTraceLog.flush();\r
-                       } catch (IOException e) {\r
-                        Activator.getDefault().logError("Error writing to log file " + LOGNAME, e); //$NON-NLS-1$\r
-                       }\r
-               }\r
-       }\r
-\r
-       public static void traceIndex(String msg) {\r
-           String message = ("[INDEX] " + msg);\r
-           trace(message);\r
-       }\r
-       \r
-       public static void traceDisplay(String msg) {\r
-               String message = ("[DISPLAY]" + msg);\r
-               trace(message);\r
-       }\r
-\r
-       public static void traceSorting(String msg) {\r
-               String message = ("[SORT] " + msg);\r
-               trace(message);\r
-       }\r
-\r
-       public static void traceError(String msg) {\r
-               String message = ("[ERR] Thread=" + Thread.currentThread().getId() + " " + msg);\r
-               trace(message);\r
-       }\r
-\r
-       public static void traceWarning(String msg) {\r
-           String message = ("[WARN] Thread=" + Thread.currentThread().getId() + " " + msg);\r
-           trace(message);\r
-       }\r
-       \r
-       public static void traceInfo(String msg) {\r
-               String message = ("[INF] Thread=" + Thread.currentThread().getId() + " " + msg);\r
-               trace(message);\r
-       }\r
-       \r
-       \r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.ui;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * Tracer class for the tmf.ui plugin
+ */
+@SuppressWarnings("nls")
+public class TmfUiTracer {
+
+    private static String pluginID = Activator.PLUGIN_ID;
+
+    static Boolean ERROR   = Boolean.FALSE;
+    static Boolean WARNING = Boolean.FALSE;
+    static Boolean INFO    = Boolean.FALSE;
+
+    static Boolean INDEX   = Boolean.FALSE;
+    static Boolean DISPLAY = Boolean.FALSE;
+    static Boolean SORTING = Boolean.FALSE;
+
+    private static String LOGNAME = "traceUI.log";
+    private static BufferedWriter fTraceLog = null;
+
+    private static BufferedWriter openLogFile(String filename) {
+        BufferedWriter outfile = null;
+        try {
+            outfile = new BufferedWriter(new FileWriter(filename));
+        } catch (IOException e) {
+            Activator.getDefault().logError("Error creating log file " + LOGNAME, e); //$NON-NLS-1$
+        }
+        return outfile;
+    }
+
+    /**
+     * Initialize tracing
+     */
+    public static void init() {
+
+        String traceKey;
+        boolean isTracing = false;
+
+        traceKey = Platform.getDebugOption(pluginID + "/error");
+        if (traceKey != null) {
+            ERROR = (Boolean.valueOf(traceKey)).booleanValue();
+            isTracing |= ERROR;
+        }
+
+        traceKey = Platform.getDebugOption(pluginID + "/warning");
+        if (traceKey != null) {
+            WARNING = (Boolean.valueOf(traceKey)).booleanValue();
+            isTracing |= WARNING;
+        }
+
+        traceKey = Platform.getDebugOption(pluginID + "/info");
+        if (traceKey != null) {
+            INFO = (Boolean.valueOf(traceKey)).booleanValue();
+            isTracing |= INFO;
+        }
+
+        traceKey = Platform.getDebugOption(pluginID + "/updateindex");
+        if (traceKey != null) {
+            INDEX = (Boolean.valueOf(traceKey)).booleanValue();
+            isTracing |= INDEX;
+        }
+
+        traceKey = Platform.getDebugOption(pluginID + "/display");
+        if (traceKey != null) {
+            DISPLAY = (Boolean.valueOf(traceKey)).booleanValue();
+            isTracing |= DISPLAY;
+        }
+
+        traceKey = Platform.getDebugOption(pluginID + "/sorting");
+        if (traceKey != null) {
+            SORTING = (Boolean.valueOf(traceKey)).booleanValue();
+            isTracing |= SORTING;
+        }
+
+        // Create trace log file if needed
+        if (isTracing) {
+            fTraceLog = openLogFile(LOGNAME);
+        }
+    }
+
+    /**
+     * Stop tracing
+     */
+    public static void stop() {
+        if (fTraceLog == null) {
+            return;
+        }
+
+        try {
+            fTraceLog.close();
+            fTraceLog = null;
+        } catch (IOException e) {
+            Activator.getDefault().logError("Error closing log file " + LOGNAME, e); //$NON-NLS-1$
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Predicates
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return If ERROR messages are traced
+     */
+    public static boolean isErrorTraced() {
+        return ERROR;
+    }
+
+    /**
+     * @return If INDEX messages are traced
+     */
+    public static boolean isIndexTraced() {
+        return INDEX;
+    }
+
+    /**
+     * @return If DISPLAY messages are traced
+     */
+    public static boolean isDisplayTraced() {
+        return DISPLAY;
+    }
+
+    /**
+     * @return If SORTING messages are traced
+     */
+    public static boolean isSortingTraced() {
+        return SORTING;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Tracing methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Trace a generic event
+     *
+     * @param msg
+     *            The event's message
+     */
+    public static void trace(String msg) {
+        long currentTime = System.currentTimeMillis();
+        StringBuilder message = new StringBuilder("[");
+        message.append(currentTime / 1000);
+        message.append(".");
+        message.append(String.format("%1$03d", currentTime % 1000));
+        message.append("] ");
+        message.append(msg);
+
+        if (fTraceLog != null) {
+            try {
+                fTraceLog.write(message.toString());
+                fTraceLog.newLine();
+                fTraceLog.flush();
+            } catch (IOException e) {
+                Activator.getDefault().logError("Error writing to log file " + LOGNAME, e); //$NON-NLS-1$
+            }
+        }
+    }
+
+    /**
+     * Trace an INDEX event
+     *
+     * @param msg
+     *            The event's message
+     */
+    public static void traceIndex(String msg) {
+        String message = ("[INDEX] " + msg);
+        trace(message);
+    }
+
+    /**
+     * Trace a DISPLAY event
+     *
+     * @param msg
+     *            The event's message
+     */
+    public static void traceDisplay(String msg) {
+        String message = ("[DISPLAY]" + msg);
+        trace(message);
+    }
+
+    /**
+     * Trace a SORTING event
+     *
+     * @param msg
+     *            The event's message
+     */
+    public static void traceSorting(String msg) {
+        String message = ("[SORT] " + msg);
+        trace(message);
+    }
+
+    /**
+     * Trace an ERROR event
+     *
+     * @param msg
+     *            The event's message
+     */
+    public static void traceError(String msg) {
+        String message = ("[ERR] Thread=" + Thread.currentThread().getId() + " " + msg);
+        trace(message);
+    }
+
+    /**
+     * Trace a WARNING event
+     *
+     * @param msg
+     *            The event's message
+     */
+    public static void traceWarning(String msg) {
+        String message = ("[WARN] Thread=" + Thread.currentThread().getId() + " " + msg);
+        trace(message);
+    }
+
+    /**
+     * Trace an INFO event
+     *
+     * @param msg
+     *            The event's message
+     */
+    public static void traceInfo(String msg) {
+        String message = ("[INF] Thread=" + Thread.currentThread().getId() + " " + msg);
+        trace(message);
+    }
+
+}
This page took 0.028678 seconds and 5 git commands to generate.