changeset 11400:37446655527c

changed log indentation increment to 2 spaces show complete scope when logging
author Doug Simon <doug.simon@oracle.com>
date Fri, 23 Aug 2013 15:19:40 +0200
parents c8a9914b36e8
children 2d228d304247 1688781c0238
files graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java
diffstat 1 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java	Fri Aug 23 14:03:09 2013 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java	Fri Aug 23 15:19:40 2013 +0200
@@ -32,23 +32,32 @@
 
     private final class IndentImpl implements Indent {
 
+        private static final String INDENTATION_INCREMENT = "  ";
+
         final String indent;
         boolean enabled;
         final IndentImpl parentIndent;
 
         IndentImpl(IndentImpl parentIndent, boolean enabled) {
             this.parentIndent = parentIndent;
-            this.indent = (parentIndent == null ? "" : parentIndent.indent + "    ");
+            this.indent = (parentIndent == null ? "" : parentIndent.indent + INDENTATION_INCREMENT);
             this.enabled = enabled;
         }
 
+        private void printScopeName() {
+            if (logScopeName) {
+                if (parentIndent != null) {
+                    parentIndent.printScopeName();
+                }
+                output.println(indent + "[thread:" + Thread.currentThread().getId() + "] scope: " + qualifiedName);
+                logScopeName = false;
+            }
+        }
+
         @Override
         public void log(String msg, Object... args) {
             if (enabled) {
-                if (logScopeName) {
-                    output.println(indent + "scope: " + qualifiedName);
-                    logScopeName = false;
-                }
+                printScopeName();
                 output.println(indent + String.format(msg, args));
                 lastUsedIndent = this;
             }
@@ -86,13 +95,13 @@
     private static DebugTimer scopeTime = Debug.timer("ScopeTime");
 
     private final DebugScope parent;
-    private IndentImpl lastUsedIndent = null;
-    private boolean logScopeName = false;
+    private IndentImpl lastUsedIndent;
+    private boolean logScopeName;
 
     private Object[] context;
 
-    private DebugValueMap valueMap;
-    private String qualifiedName;
+    private final DebugValueMap valueMap;
+    private final String qualifiedName;
 
     private static final char SCOPE_SEP = '.';
 
@@ -123,10 +132,10 @@
         this.context = context;
         this.qualifiedName = qualifiedName;
         if (parent != null) {
-            this.lastUsedIndent = new IndentImpl(parent.lastUsedIndent, parent.isLogEnabled());
+            lastUsedIndent = new IndentImpl(parent.lastUsedIndent, parent.isLogEnabled());
             logScopeName = !parent.qualifiedName.equals(qualifiedName);
         } else {
-            this.lastUsedIndent = new IndentImpl(null, false);
+            lastUsedIndent = new IndentImpl(null, false);
             logScopeName = true;
         }
 
@@ -175,10 +184,7 @@
 
     public void printf(String msg, Object... args) {
         if (isLogEnabled()) {
-            if (logScopeName) {
-                output.println("scope: " + qualifiedName);
-                logScopeName = false;
-            }
+            lastUsedIndent.printScopeName();
             output.printf(msg, args);
         }
     }