//
// DebugTools.java
//

/*
LOCI Common package: utilities for I/O, reflection and miscellaneous tasks.
Copyright (C) 2005-@year@ Melissa Linkert, Curtis Rueden and Chris Allan.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.common;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/**
 * A utility class with convenience methods for debugging.
 *
 * <dl><dt><b>Source code:</b></dt>
 * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/common/src/loci/common/DebugTools.java">Trac</a>,
 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/components/common/src/loci/common/DebugTools.java">SVN</a></dd></dl>
 *
 * @author Curtis Rueden ctrueden at wisc.edu
 */
public final class DebugTools {

  // -- Constructor --

  private DebugTools() { }

  // -- DebugTools methods --

  /** Extracts the given exception's corresponding stack trace to a string. */
  public static String getStackTrace(Throwable t) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    t.printStackTrace(new PrintStream(out));
    return new String(out.toByteArray());
  }

}

@@ -940,16 +940,46 @@
 tStream;
+%0Aimport java.util.Enumeration;
 %0A%0A/**%0A *
@@ -1796,10 +1796,1195 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Attempts to enable SLF4J logging via log4j%0A   * without an external configuration file.%0A   *%0A   * @param level A string indicating the desired level%0A   *   (i.e.: ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARN).%0A   * @return true iff logging was successfully enabled%0A   */%0A  public static synchronized boolean enableLogging(String level) %7B%0A    ReflectedUniverse r = new ReflectedUniverse();%0A    try %7B%0A      r.exec(%22import org.apache.log4j.Level%22);%0A      r.exec(%22import org.apache.log4j.Logger%22);%0A      r.exec(%22root = Logger.getRootLogger()%22);%0A      r.exec(%22root.setLevel(Level.%22 + level + %22)%22);%0A      Enumeration en = (Enumeration) r.exec(%22root.getAllAppenders()%22);%0A      if (!en.hasMoreElements()) %7B%0A        // no appenders yet; attach a simple console appender%0A        r.exec(%22import org.apache.log4j.ConsoleAppender%22);%0A        r.exec(%22import org.apache.log4j.PatternLayout%22);%0A        r.setVar(%22pattern%22, %22%25m%25n%22);%0A        r.exec(%22layout = new PatternLayout(pattern)%22);%0A        r.exec(%22appender = new ConsoleAppender(layout)%22);%0A        r.exec(%22root.addAppender(appender)%22);%0A      %7D%0A    %7D%0A    catch (ReflectException exc) %7B%0A      return false;%0A    %7D%0A    return true;%0A  %7D%0A%0A
 %7D%0A

Add a utility method for enabling log4j logging without a configuration file.