tmf: Add the view ID to some JUL log statements of time graph views
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Fri, 15 Jul 2016 13:18:14 +0000 (09:18 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Fri, 9 Sep 2016 19:01:38 +0000 (15:01 -0400)
This patch adds a getViewId() method to AbstractTimeGraphView that returns the
view's primaryID:secondaryID string corresponding to the view. This view ID is
added to some JUL log statements.

Change-Id: Ica415d919883822676f0f1c107bcd3b631ea9c67
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/77395
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/TmfView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java

index 555711dcfc34fb04a7f0fff055e025a93a62f342..455b631d8f791040d58b39a9200e5215c37f42cb 100644 (file)
@@ -26,6 +26,7 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.part.ViewPart;
@@ -200,4 +201,20 @@ public abstract class TmfView extends ViewPart implements ITmfComponent {
     public Composite getParentComposite() {
         return fParentComposite;
     }
+
+    /**
+     * Return the Eclipse view ID in the format <Primary ID>:<Secondary ID> or
+     * simply <Primary ID> if secondary ID is null
+     *
+     * @return This view's view ID
+     * @since 2.1
+     */
+    protected String getViewId() {
+        IViewSite viewSite = getViewSite();
+        String secondaryId = viewSite.getSecondaryId();
+        if (secondaryId == null) {
+            return viewSite.getId();
+        }
+        return viewSite.getId() + ':' + secondaryId;
+    }
 }
index 8bd3d62594dd39534bc3544c0d82adfd012de43a..f1414d453e9167c4a72577bd6815d2b288873e92 100644 (file)
@@ -150,6 +150,8 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
     private static final Pattern RGBA_PATTERN = Pattern.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
 
     private static final Logger LOGGER = TraceCompassLog.getLogger(AbstractTimeGraphView.class);
+    private static final String LOG_STRING_WITH_PARAM = "[TimeGraphView:%s] viewId=%s, %s"; //$NON-NLS-1$
+    private static final String LOG_STRING = "[TimeGraphView:%s] viewId=%s"; //$NON-NLS-1$
 
     /**
      * Redraw state enum
@@ -703,14 +705,14 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         }
 
         public void run(IProgressMonitor monitor) {
-            LOGGER.info(() -> "[TimeGraphView:BuildJobStart] trace=" + fBuildTrace.getName()); //$NON-NLS-1$
+            LOGGER.info(() -> getLogMessage("BuildThreadStart", "trace=" + fBuildTrace.getName())); //$NON-NLS-1$ //$NON-NLS-2$
 
             buildEntryList(fBuildTrace, fParentTrace, NonNullUtils.checkNotNull(monitor));
             synchronized (fBuildJobMap) {
                 fBuildJobMap.remove(fBuildTrace);
             }
 
-            LOGGER.info(() -> "[TimeGraphView:BuildJobEnd]"); //$NON-NLS-1$
+            LOGGER.info(() -> getLogMessage("BuildThreadEnd", null)); //$NON-NLS-1$
         }
     }
 
@@ -779,12 +781,12 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
 
         @Override
         public final void run() {
-            LOGGER.info(() -> "[TimeGraphView:ZoomThreadStart] start=" + fZoomStartTime + ", end=" + fZoomEndTime); //$NON-NLS-1$ //$NON-NLS-2$
+            LOGGER.info(() -> getLogMessage("ZoomThreadStart", "start=" + fZoomStartTime + ", end=" + fZoomEndTime)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
             doRun();
             fDirty.decrementAndGet();
 
-            LOGGER.info(() -> "[TimeGraphView:ZoomThreadEnd]"); //$NON-NLS-1$
+            LOGGER.info(() -> getLogMessage("ZoomThreadEnd", null)); //$NON-NLS-1$
         }
 
         /**
@@ -822,11 +824,11 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
 
         @Override
         public void doRun() {
-            LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingStates]"); //$NON-NLS-1$
+            LOGGER.config(() -> getLogMessage("ZoomThreadGettingStates", null)); //$NON-NLS-1$
 
             for (TimeGraphEntry entry : fZoomEntryList) {
                 if (getMonitor().isCanceled()) {
-                    LOGGER.info(() -> "[TimeGraphView:ZoomThreadCanceled]"); //$NON-NLS-1$
+                    LOGGER.info(() -> getLogMessage("ZoomThreadCanceled", null)); //$NON-NLS-1$
                     return;
                 }
                 if (entry == null) {
@@ -835,11 +837,11 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                 zoom(entry, getMonitor());
             }
             /* Refresh the arrows when zooming */
-            LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingLinks]"); //$NON-NLS-1$
+            LOGGER.config(() -> getLogMessage("ZoomThreadGettingLinks", null)); //$NON-NLS-1$
             List<ILinkEvent> events = getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
 
             /* Refresh the view-specific markers when zooming */
-            LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingMarkers]"); //$NON-NLS-1$
+            LOGGER.config(() -> getLogMessage("ZoomThreadGettingMarkers", null)); //$NON-NLS-1$
             List<IMarkerEvent> markers = new ArrayList<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
             /* Refresh the trace-specific markers when zooming */
             markers.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
@@ -1259,6 +1261,25 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         return fFindTarget;
     }
 
+    /**
+     * Formats a log message for this class
+     *
+     * @param event
+     *            The event to log, that will be appended to the class name to
+     *            make the full event name
+     * @param parameters
+     *            The string of extra parameters to add to the log message, in
+     *            the format name=value[, name=value]*, or <code>null</code> for
+     *            no params
+     * @return The complete log message for this class
+     */
+    private String getLogMessage(String event, @Nullable String parameters) {
+        if (parameters == null) {
+            return String.format(LOG_STRING, event, getViewId());
+        }
+        return String.format(LOG_STRING_WITH_PARAM, event, getViewId(), parameters);
+    }
+
     // ------------------------------------------------------------------------
     // ViewPart
     // ------------------------------------------------------------------------
@@ -1598,7 +1619,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         }
         fTrace = trace;
 
-        LOGGER.info(() -> "[TimeGraphView:LoadingTrace] trace=" + trace.getName()); //$NON-NLS-1$
+        LOGGER.info(() -> getLogMessage("LoadingTrace", "trace=" + trace.getName())); //$NON-NLS-1$ //$NON-NLS-2$
 
         restoreViewContext();
         fEditorFile = TmfTraceManager.getInstance().getTraceEditorFile(trace);
@@ -1828,12 +1849,12 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
      * Refresh the display
      */
     protected void refresh() {
-        LOGGER.info(() -> "[TimeGraphView:RefreshRequested]"); //$NON-NLS-1$
+        LOGGER.info(() -> getLogMessage("RefreshRequested", null)); //$NON-NLS-1$
         final boolean zoomThread = Thread.currentThread() instanceof ZoomThread;
         TmfUiRefreshHandler.getInstance().queueUpdate(this, new Runnable() {
             @Override
             public void run() {
-                LOGGER.info(() -> "[TimeGraphView:RefreshStart]"); //$NON-NLS-1$
+                LOGGER.info(() -> getLogMessage("RefreshStart", null)); //$NON-NLS-1$
                 if (fTimeGraphWrapper.isDisposed()) {
                     return;
                 }
@@ -1918,7 +1939,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                     startZoomThread(startTime, endTime);
                 }
                 fDirty.decrementAndGet();
-                LOGGER.info(() -> "[TimeGraphView:RefreshEnd]"); //$NON-NLS-1$
+                LOGGER.info(() -> getLogMessage("RefreshEnd", null)); //$NON-NLS-1$
             }
         });
     }
@@ -1935,11 +1956,11 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                 return;
             }
         }
-        LOGGER.info(() -> "[TimeGraphView:RedrawRequested]"); //$NON-NLS-1$
+        LOGGER.info(() -> getLogMessage("RedrawRequested", null)); //$NON-NLS-1$
         Display.getDefault().asyncExec(new Runnable() {
             @Override
             public void run() {
-                LOGGER.info(() -> "[TimeGraphView:RedrawStart]"); //$NON-NLS-1$
+                LOGGER.info(() -> getLogMessage("RedrawStart", null)); //$NON-NLS-1$
                 if (fTimeGraphWrapper.isDisposed()) {
                     return;
                 }
@@ -1953,7 +1974,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                         fRedrawState = State.IDLE;
                     }
                 }
-                LOGGER.info(() -> "[TimeGraphView:RedrawEnd]"); //$NON-NLS-1$
+                LOGGER.info(() -> getLogMessage("RedrawEnd", null)); //$NON-NLS-1$
             }
         });
     }
This page took 0.028615 seconds and 5 git commands to generate.