Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* Debugger provides useful methods for obtaining exception stack traces.
* It can build reader friendly strings for objects
* that do not implement their toString method.
*
* It also provides a set of print functions
* to log DEBUG, INFO, WARN and FATAL level messages using
* the Debugger.println(...), Debugger.printInfo(...),
* Debugger.printWarn(...) and Debugger.printFatal(...) methods respectively.
*
* The default log object implementation is solutions.global.operations.Log4J.
*
* Set the configuration property to plug-in another logger (@see Config more information);
*
* Log.class=className
*
* The logClass class name indicated must implement the
* nyla.solutions.core.operations.Log interface.
*
*
*
*
*
* @author Gregory Green
* @version 1.5
*/
public class Debugger
{
//For println level messaging
private static boolean DEBUG = settings().getPropertyBoolean(Debugger.class,"DEBUG",true).booleanValue();
private static Log defaultLogger;
/**
* LOG_CLASS_NAME_PROP = "Log.logClass"
*/
public static final String LOG_CLASS_NAME_PROP = "Log.class";
private static Class> logClass;
private static HashMap, Log> logMap = new HashMap, Log>();
static
{
try
{
logClass = Class.forName(settings().getProperty(LOG_CLASS_NAME_PROP,
SystemOutLog.class.getName()));
defaultLogger = (Log) ClassPath.newInstance(logClass);
}
catch(SetupException e)
{
throw e;
}
catch(ConfigException e)
{
throw e;
}
catch (RuntimeException e)
{
throw new SetupException(e);
}
catch (NoClassDefFoundError e)
{
throw new SetupException("Check value of "+LOG_CLASS_NAME_PROP+" in confi file"+Config.getLocation(),e);
}
catch (ClassNotFoundException e)
{
throw new SetupException("Check value of "+LOG_CLASS_NAME_PROP+" in confi file"+Config.getLocation(),e);
}
} // ------------------------------------------------------
/**
*
*
*
* @param c the calling class
*
* @return the log 4 J category
*/
/**
*
* @param c the calling class
* @return the logger implementation
*/
@SuppressWarnings("rawtypes")
public static Log getLog(Class c)
{
try
{
if (c == null || logClass == null)
return defaultLogger;
// check cache
Log logger = logMap.get(c);
if (logger == null)
{
// create an put in map
logger = (Log) ClassPath.newInstance(logClass);
logger.setLoggingClass(c);
logMap.put(c, logger);
}
return logger;
}
catch (Exception e)
{
e.printStackTrace();
return defaultLogger;
}
} // -----------------------------------------------
/**
*
* convert throwable to a stack trace
*
* @param t the throwable
*
* @return the stack trace string
*/
public static String stackTrace(Throwable t)
{
if (t == null)
{
return "Debugger.stackTrace(null) NULL EXCEPTION (NO TRACE AVAILABLE)!!";
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
return sw.toString();
} // -----------------------------------------
/**
*
* @param obj input object
* @return the string representation
*/
public static String toString(Object obj)
{
return toString(obj, new HashSet