Methods Summary |
---|
private static void | diagLoggerLog(java.lang.String str)
diag_logger.log(str);
|
private static void | diagLoggerLogAndOut(java.lang.String str, boolean stderr)
// handle possible recursive initialisation problems where the init of diag-logger gets
// back here....
if ( diag_logger == null ){
if ( stderr ){
System.err.println( str );
}else{
System.out.println( str );
}
}else{
diag_logger.logAndOut( str, stderr );
}
|
private static void | diagLoggerLogAndOut(java.lang.Throwable e)
// handle possible recursive initialisation problems where the init of diag-logger gets
// back here....
if ( diag_logger == null ){
e.printStackTrace();
}else{
diag_logger.logAndOut( e );
}
|
public static void | dumpSystemProperties()
out( "System Properties:");
Properties props = System.getProperties();
Iterator it = props.keySet().iterator();
while(it.hasNext()){
String name = (String)it.next();
out( "\t".concat(name).concat(" = '").concat(props.get(name).toString()).concat("'" ));
}
|
public static void | dumpThreads(java.lang.String name)
out(name+":");
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
dumpThreads( threadGroup, "\t" );
|
public static void | dumpThreads(java.lang.ThreadGroup threadGroup, java.lang.String indent)
Thread[] threadList = new Thread[threadGroup.activeCount()];
threadGroup.enumerate(threadList);
for (int i = 0; i < threadList.length; i++){
Thread t = threadList[i];
if ( t != null ){
out( indent.concat("active thread = ").concat(t.toString()).concat(", daemon = ").concat(String.valueOf(t.isDaemon())));
}
}
if ( threadGroup.getParent() != null ){
dumpThreads(threadGroup.getParent(),indent+"\t");
}
|
public static void | dumpThreadsLoop(java.lang.String name)
new AEThread("Thread Dumper")
{
public void
runSupport()
{
while(true){
Debug.dumpThreads(name);
try{
Thread.sleep(5000);
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
}
}.start();
|
private static java.lang.String | getCompressedStackTrace(java.lang.Throwable t, int frames_to_skip)
return getCompressedStackTrace(t, frames_to_skip, 200);
|
private static java.lang.String | getCompressedStackTrace(java.lang.Throwable t, int frames_to_skip, int iMaxLines)
String sStackTrace = "";
StackTraceElement[] st = t.getStackTrace();
int iMax = Math.min(st.length, iMaxLines + frames_to_skip);
for (int i = frames_to_skip; i < iMax; i++) {
if (i > frames_to_skip)
sStackTrace += ",";
String cn = st[i].getClassName();
cn = cn.substring( cn.lastIndexOf(".")+1);
sStackTrace += cn +"::"+st[i].getMethodName()+"::"+st[i].getLineNumber();
}
Throwable cause = t.getCause();
if (cause != null) {
sStackTrace += "\n\tCaused By: " + getCompressedStackTrace(cause, 0);
}
return sStackTrace;
|
private static java.lang.String | getCompressedStackTrace(int frames_to_skip, int iMaxLines)
String trace_trace_tail = null;
try {
throw new Exception();
} catch (Exception e) {
trace_trace_tail = getCompressedStackTrace(e, frames_to_skip, iMaxLines);
}
return (trace_trace_tail);
|
public static java.lang.String | getCompressedStackTrace()
return( getCompressedStackTrace( new Throwable(), 2 ));
|
public static java.lang.String | getCompressedStackTrace(int iMaxLines)
return( getCompressedStackTrace( new Throwable(), 2, iMaxLines ));
|
public static java.lang.String | getExceptionMessage(java.lang.Throwable e)
String message = e.getMessage();
if ( message == null || message.length() == 0 ){
message = e.getClass().getName();
int pos = message.lastIndexOf(".");
message = message.substring( pos+1 );
}else if ( e instanceof ClassNotFoundException ){
if ( message.toLowerCase().indexOf("found") == -1 ){
message = "Class " + message + " not found";
}
}
return( message );
|
public static java.lang.String | getLastCaller()
return getLastCaller(0);
|
public static java.lang.String | getLastCaller(int numToGoBackFurther)
try {
throw new Exception();
}
catch (Exception e) {
// [0] = our throw
// [1] = the line that called getLastCaller
// [2] = the line that called the function that has getLastCaller
StackTraceElement st[] = e.getStackTrace();
if (st == null || st.length == 0)
return "??";
if (st.length > 3 + numToGoBackFurther)
return st[3 + numToGoBackFurther].toString();
return st[st.length - 1].toString();
}
|
public static java.lang.String | getNestedExceptionMessage(java.lang.Throwable e)
String last_message = "";
while( e != null ){
String this_message;
if ( e instanceof UnknownHostException ){
this_message = "Unknown host " + e.getMessage();
}else{
this_message = e.getMessage();
}
if ( this_message == null || this_message.length() == 0 ){
this_message = e.getClass().getName();
int pos = this_message.lastIndexOf(".");
this_message = this_message.substring( pos+1 );
}
if ( last_message.indexOf( this_message ) == -1 ){
last_message = this_message + ( last_message.length()==0?"":(", " + last_message ));
}
e = e.getCause();
}
return( last_message );
|
public static java.lang.String | getNestedExceptionMessageAndStack(java.lang.Throwable e)
return( getNestedExceptionMessage(e) + ", " + getCompressedStackTrace( e, 0 ));
|
private static java.lang.String | getStackTrace(int endNumToSkip)
String sStackTrace = "";
try {
throw new Exception();
}
catch (Exception e) {
StackTraceElement st[] = e.getStackTrace();
for (int i = 1; i < st.length - endNumToSkip; i++) {
if (!st[i].getMethodName().endsWith("StackTrace"))
sStackTrace += st[i].toString() + "\n";
}
if (e.getCause() != null)
sStackTrace += "\tCaused By: " + getStackTrace(e.getCause()) + "\n";
}
return sStackTrace;
|
public static java.lang.String | getStackTrace(boolean bCompressed, boolean bIncludeSelf)
return getStackTrace(bCompressed, bIncludeSelf, bIncludeSelf ? 0 : 1, 200);
|
public static java.lang.String | getStackTrace(boolean bCompressed, boolean bIncludeSelf, int iNumLinesToSkip, int iMaxLines)
if (bCompressed)
return getCompressedStackTrace(bIncludeSelf ? 2 + iNumLinesToSkip
: 3 + iNumLinesToSkip, iMaxLines);
// bIncludeSelf not supported gor non Compressed yet
return getStackTrace(1);
|
public static java.lang.String | getStackTrace(java.lang.Throwable e)
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos));
e.printStackTrace(pw);
pw.close();
return baos.toString();
} catch (Throwable ignore) {
return "";
}
|
public static void | killAWTThreads()
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
killAWTThreads( threadGroup );
|
public static void | killAWTThreads(java.lang.ThreadGroup threadGroup)
Thread[] threadList = new Thread[threadGroup.activeCount()];
threadGroup.enumerate(threadList);
for (int i = 0; i < threadList.length; i++){
Thread t = threadList[i];
if ( t != null ){
String name = t.getName();
if ( name.startsWith( "AWT" )){
out( "Interrupting thread '".concat(t.toString()).concat("'" ));
t.interrupt();
}
}
}
if ( threadGroup.getParent() != null ){
killAWTThreads(threadGroup.getParent());
}
|
public static void | main(java.lang.String[] args)
System.out.println(secretFileName("c:\\temp\\hello there.txt"));
System.out.println(secretFileName("hello there.txt"));
|
public static void | out(java.lang.String _debug_message)Prints out the given debug message to System.out,
prefixed by the calling class name, method and
line number.
out( _debug_message, null );
|
public static void | out(java.lang.Throwable _exception)Prints out the given exception stacktrace to System.out,
prefixed by the calling class name, method and
line number.
out( "", _exception );
|
public static void | out(java.lang.String _debug_msg, java.lang.Throwable _exception)Prints out the given debug message to System.out,
prefixed by the calling class name, method and
line number, appending the stacktrace of the given exception.
String header = "DEBUG::";
header = header + new Date(SystemTime.getCurrentTime()).toString() + "::";
String className;
String methodName;
int lineNumber;
String trace_trace_tail = null;
try {
throw new Exception();
}
catch (Exception e) {
StackTraceElement[] st = e.getStackTrace();
StackTraceElement first_line = st[2];
className = first_line.getClassName() + "::";
methodName = first_line.getMethodName() + "::";
lineNumber = first_line.getLineNumber();
trace_trace_tail = getCompressedStackTrace(e, 3, 200);
}
diagLoggerLogAndOut(header+className+(methodName)+lineNumber+":", true);
if (_debug_msg.length() > 0) {
diagLoggerLogAndOut(" " + _debug_msg, true);
}
if ( trace_trace_tail != null ){
diagLoggerLogAndOut( " " + trace_trace_tail, true);
}
if (_exception != null) {
diagLoggerLogAndOut(_exception);
}
|
public static void | outDiagLoggerOnly(java.lang.String str)
diagLoggerLog(str);
|
public static void | outNoStack(java.lang.String str)
outNoStack( str, false );
|
public static void | outNoStack(java.lang.String str, boolean stderr)
diagLoggerLogAndOut("DEBUG::"+ new Date(SystemTime.getCurrentTime()).toString() + " " + str, stderr );
|
public static void | outStackTrace()
// skip the last, since they'll most likely be main
diagLoggerLogAndOut(getStackTrace(1),false);
|
public static void | printStackTrace(java.lang.Throwable e)
printStackTrace(e, null);
|
public static void | printStackTrace(java.lang.Throwable e, java.lang.Object context)
String header = "DEBUG::";
header = header + new Date(SystemTime.getCurrentTime()).toString() + "::";
String className = "?::";
String methodName = "?::";
int lineNumber = -1;
try {
throw new Exception();
}catch (Exception f) {
StackTraceElement[] st = f.getStackTrace();
for (int i=1;i<st.length;i++){
StackTraceElement first_line = st[i];
className = first_line.getClassName() + "::";
methodName = first_line.getMethodName() + "::";
lineNumber = first_line.getLineNumber();
// skip stuff generated by the logger
if ( className.indexOf( ".logging." ) != -1 ||
className.endsWith( ".Debug::" )){
continue;
}
break;
}
}
diagLoggerLogAndOut(header+className+(methodName)+lineNumber+":", true);
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter( new OutputStreamWriter( baos ));
if (context!=null) {pw.print(" "); pw.println(context);}
pw.print(" ");
e.printStackTrace( pw );
pw.close();
String stack = baos.toString();
diagLoggerLogAndOut(stack, true );
}catch( Throwable ignore ){
e.printStackTrace();
}
|
public static java.lang.String | secretFileName(java.lang.String key)
if (key == null)
return "";
final String sep = File.separator;
final String regex = "([\\" + sep + "]?[^\\" + sep + "]{0,3}+)[^\\" + sep
+ "]*";
String secretName = key.replaceAll(regex, "$1");
int iExtensionPos = key.lastIndexOf(".");
if (iExtensionPos >= 0)
secretName += key.substring(iExtensionPos);
return secretName;
|