# HG changeset patch # User Erik Eckstein # Date 1395824785 -3600 # Node ID 3128becfec959c16fe31409f358b75744b4861c7 # Parent 164903a50a9a6d9dd12edb69496d5f5885c45115 add Debug.logAndIndent with enabled-flag diff -r 164903a50a9a -r 3128becfec95 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 Wed Mar 26 10:04:37 2014 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Wed Mar 26 10:06:25 2014 +0100 @@ -456,6 +456,73 @@ return noLoggerInstance; } + /** + * A convenience function which combines enabling/disabling of logging and + * {@link #logAndIndent(String, Object...)}. Note: Use this method with care because it + * overrules the -G:Log option. + * + * @param enabled Flag for enabling or disabling logging + * @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#logAndIndent + */ + public static Indent logAndIndent(boolean enabled, String msg, Object... args) { + if (ENABLED) { + Collection dumpHandlers; + PrintStream output; + DebugConfig currentConfig = DebugScope.getConfig(); + if (currentConfig != null) { + dumpHandlers = currentConfig.dumpHandlers(); + output = currentConfig.output(); + } else { + dumpHandlers = Collections. emptyList(); + output = System.out; + } + DebugConfigScope configScope = new DebugConfigScope(Debug.fixedConfig(enabled, Debug.isDumpEnabled(), false, false, dumpHandlers, output)); + return new IndentWithEnable(Debug.logAndIndent(msg, args), configScope); + } + return noLoggerInstance; + } + + private static class IndentWithEnable implements Indent { + + Indent delegate; + DebugConfigScope configScope; + + IndentWithEnable(Indent delegate, DebugConfigScope configScope) { + this.delegate = delegate; + this.configScope = configScope; + } + + @Override + public void log(String msg, Object... args) { + delegate.log(msg, args); + } + + @Override + public Indent indent() { + return delegate.indent(); + } + + @Override + public Indent logAndIndent(String msg, Object... args) { + return delegate.logAndIndent(msg, args); + } + + @Override + public Indent outdent() { + configScope.close(); + return delegate.outdent(); + } + + @Override + public void close() { + configScope.close(); + delegate.close(); + } + } + public static Iterable context() { if (ENABLED) { return DebugScope.getInstance().getCurrentContext();