# HG changeset patch # User Erik Eckstein # Date 1385383278 -3600 # Node ID 401830ff96f426d278d480f3aa86b52570b3aaf4 # Parent 333ec6116aa7c98ad7222d6a082baa16a05ae054 some improvements in Debug logging diff -r 333ec6116aa7 -r 401830ff96f4 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Nov 25 13:37:24 2013 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Nov 25 13:41:18 2013 +0100 @@ -231,7 +231,7 @@ } @Override - public Indent logIndent(String msg, Object... args) { + public Indent logAndIndent(String msg, Object... args) { return this; } @@ -240,6 +240,9 @@ return this; } + @Override + public void close() { + } } private static final NoLogger noLoggerInstance = new NoLogger(); @@ -281,9 +284,9 @@ * @param msg The format string of the log message * @param args The arguments referenced by the log message string * @return The new indentation level - * @see Indent#logIndent + * @see Indent#logAndIndent */ - public static Indent logIndent(String msg, Object... args) { + public static Indent logAndIndent(String msg, Object... args) { if (ENABLED) { DebugScope scope = DebugScope.getInstance(); scope.log(msg, args); @@ -300,7 +303,7 @@ * @param args The arguments referenced by the log message string * @return The new indentation level */ - public static Indent logIndent(boolean enabled, String msg, Object... args) { + public static Indent logAndIndent(boolean enabled, String msg, Object... args) { if (ENABLED) { DebugScope scope = DebugScope.getInstance(); boolean saveLogEnabled = scope.isLogEnabled(); diff -r 333ec6116aa7 -r 401830ff96f4 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Indent.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Indent.java Mon Nov 25 13:37:24 2013 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Indent.java Mon Nov 25 13:41:18 2013 +0100 @@ -48,8 +48,20 @@ * in.outdent(); * } * + * + * Example usage with try-with-resources: + * + *
+ * 
+ *      try (Indent in = Debug.logIndent("header message")) {
+ *          ...
+ *          in.log("message");
+ *          ...
+ *      }
+ * 
+ * 
*/ -public interface Indent { +public interface Indent extends AutoCloseable { /** * Prints an indented message to the DebugLevel's logging stream if logging is enabled. @@ -81,9 +93,9 @@ * @param msg The format string of the log message * @param args The arguments referenced by the log message string * @return The new indentation level - * @see Debug#logIndent + * @see Debug#logAndIndent */ - Indent logIndent(String msg, Object... args); + Indent logAndIndent(String msg, Object... args); /** * Restores the previous indent level. Calling this method is important to restore the correct @@ -92,4 +104,6 @@ * @return The indent level from which this Indent was created. */ Indent outdent(); + + void close(); } diff -r 333ec6116aa7 -r 401830ff96f4 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java Mon Nov 25 13:37:24 2013 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java Mon Nov 25 13:41:18 2013 +0100 @@ -75,7 +75,7 @@ } @Override - public Indent logIndent(String msg, Object... args) { + public Indent logAndIndent(String msg, Object... args) { log(msg, args); return indent(); } @@ -87,6 +87,11 @@ } return lastUsedIndent; } + + @Override + public void close() { + outdent(); + } } private static ThreadLocal instanceTL = new ThreadLocal<>(); @@ -231,7 +236,6 @@ public T scope(String newName, Runnable runnable, Callable callable, boolean sandbox, DebugConfig sandboxConfig, Object[] newContext) { DebugScope oldContext = getInstance(); DebugConfig oldConfig = getConfig(); - boolean oldLogEnabled = oldContext.isLogEnabled(); DebugScope newChild = null; if (sandbox) { newChild = new DebugScope(newName, newName, null, newContext); @@ -240,6 +244,7 @@ newChild = oldContext.createChild(newName, newContext); } instanceTL.set(newChild); + newChild.setLogEnabled(oldContext.isLogEnabled()); newChild.updateFlags(); try { return executeScope(runnable, callable); @@ -247,7 +252,6 @@ newChild.context = null; instanceTL.set(oldContext); setConfig(oldConfig); - setLogEnabled(oldLogEnabled); } } @@ -283,7 +287,6 @@ meterEnabled = false; timeEnabled = false; dumpEnabled = false; - setLogEnabled(false); // Be pragmatic: provide a default log stream to prevent a crash if the stream is not // set while logging @@ -293,7 +296,9 @@ timeEnabled = config.isTimeEnabled(); dumpEnabled = config.isDumpEnabled(); output = config.output(); - setLogEnabled(config.isLogEnabled()); + if (config.isLogEnabled()) { + setLogEnabled(true); + } } }