Package loci.common
Class DebugTools
- java.lang.Object
-
- loci.common.DebugTools
-
public final class DebugTools extends Object
A utility class with convenience methods for debugging.- Author:
- Curtis Rueden ctrueden at wisc.edu
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
enableIJLogging(boolean debug)
Enable SLF4J logging using logback, in the context of ImageJ.static boolean
enableLogging()
Attempts to enable SLF4J logging via logback or log4j.static boolean
enableLogging(String level)
Attempts to enable SLF4J logging and set the root logger level.static String
getFieldName(Class<?> c, int value)
This method uses reflection to scan the values of the given class's static fields, returning the first matching field's name.static String
getStackTrace(Throwable t)
Extracts the given exception's corresponding stack trace to a string.static boolean
isEnabled()
Checks whether SLF4J logging has been enabled via logback or log4j.static void
setRootLevel(String level)
Sets the root logger level.
-
-
-
Method Detail
-
getStackTrace
public static String getStackTrace(Throwable t)
Extracts the given exception's corresponding stack trace to a string.- Parameters:
t
- the Throwable from which to extract a stack trace- Returns:
- the complete stack trace as a String
-
isEnabled
public static boolean isEnabled()
Checks whether SLF4J logging has been enabled via logback or log4j.- Returns:
true
if logging has been successfully enabled
-
setRootLevel
public static void setRootLevel(String level)
Sets the root logger level. This method will override the root logger level independently of the way the logging framework has been enabled.- Parameters:
level
- A string indicating the desired level
-
enableLogging
public static boolean enableLogging()
Attempts to enable SLF4J logging via logback or log4j. This will first check whether the logging has been enabled using the return value ofisEnabled()
.- Returns:
true
if logging was successfully enabled by this method
-
enableLogging
public static boolean enableLogging(String level)
Attempts to enable SLF4J logging and set the root logger level. This method will first try to initialize the logging usingenableLogging()
. If this method returnstrue
, the root logger level is also set viasetRootLevel(String)
using the input level.- Parameters:
level
- A string indicating the desired level- Returns:
true
if logging was successfully enabled by this method
-
enableIJLogging
public static boolean enableIJLogging(boolean debug)
Enable SLF4J logging using logback, in the context of ImageJ. This allows logging events to be echoed to the ImageJ status bar, regardless of how the logging configuration file was set up.- Parameters:
debug
- true if debug-level output should be shown- Returns:
- whether or not ImageJ log enabling was successful
-
getFieldName
public static String getFieldName(Class<?> c, int value)
This method uses reflection to scan the values of the given class's static fields, returning the first matching field's name.- Parameters:
c
- the class to scanvalue
- the int value of the field to find- Returns:
- the name of the field, or the string representation of
value
if a matching field is not found
-
-