List of usage examples for java.lang StackTraceElement getLineNumber
public int getLineNumber()
From source file:Main.java
public static String getFileLineMethod() { StackTraceElement traceElement = ((new Exception()).getStackTrace())[1]; StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getFileName()).append(" | ") .append(traceElement.getLineNumber()).append(" | ").append(traceElement.getMethodName()) .append("()").append("]"); return toStringBuffer.toString(); }
From source file:Main.java
private static String formatStackTraceElement(StackTraceElement ste) { return compressClassName(ste.getClassName()) + "." + ste.getMethodName() + (ste.isNativeMethod() ? "(Native Method)" : (ste.getFileName() != null && ste.getLineNumber() >= 0 ? "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")" : (ste.getFileName() != null ? "(" + ste.getFileName() + ")" : "(Unknown Source)"))); }
From source file:Main.java
public static String TAG() { StackTraceElement stacktrace = Thread.currentThread().getStackTrace()[3]; return "NITRO:" + stacktrace.getClassName().substring("com.qweex.callisto".length() + 1) + ":" + stacktrace.getMethodName() + "::" + stacktrace.getLineNumber(); }
From source file:Main.java
protected static void _printThreads(ThreadMXBean bean, long[] ids, StringBuilder sb) { ThreadInfo[] threads = bean.getThreadInfo(ids, 20); for (ThreadInfo info : threads) { if (info == null) continue; sb.append(info.getThreadName()).append(":\n"); StackTraceElement[] stack_trace = info.getStackTrace(); for (StackTraceElement el : stack_trace) { sb.append(" at ").append(el.getClassName()).append(".").append(el.getMethodName()); sb.append("(").append(el.getFileName()).append(":").append(el.getLineNumber()).append(")"); sb.append("\n"); }/*w ww .j av a 2s . com*/ sb.append("\n\n"); } }
From source file:Main.java
public static void openFeedback(Activity activity) { try {/*w ww . ja v a 2 s . com*/ throw new Exception(); } catch (Exception e) { ApplicationErrorReport report = new ApplicationErrorReport(); report.packageName = report.processName = activity.getApplication().getPackageName(); report.time = System.currentTimeMillis(); report.type = ApplicationErrorReport.TYPE_CRASH; report.systemApp = false; ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo(); crash.exceptionClassName = e.getClass().getSimpleName(); crash.exceptionMessage = e.getMessage(); StringWriter writer = new StringWriter(); PrintWriter printer = new PrintWriter(writer); e.printStackTrace(printer); crash.stackTrace = writer.toString(); StackTraceElement stack = e.getStackTrace()[0]; crash.throwClassName = stack.getClassName(); crash.throwFileName = stack.getFileName(); crash.throwLineNumber = stack.getLineNumber(); crash.throwMethodName = stack.getMethodName(); report.crashInfo = crash; Intent intent = new Intent(Intent.ACTION_APP_ERROR); intent.putExtra(Intent.EXTRA_BUG_REPORT, report); activity.startActivity(intent); } }
From source file:Main.java
public static final void log(String message) { StackTraceElement ste = Thread.currentThread().getStackTrace()[3]; String className = ste.getClassName(); className = className.substring(className.lastIndexOf(".") + 1); String methodName = ste.getMethodName(); int lineNum = ste.getLineNumber(); String logText = String.format("%s(%s):%s", methodName, lineNum, message); Log.d(className, logText);//from w ww. j av a 2 s .c o m }
From source file:Main.java
public static String getLocation(int back) { try {/*from w w w . j a v a 2 s . c o m*/ // Use Throwable to obtain stack trace, using Thread.currentThread().getStackTrace is expensive because of thread-safety */ StackTraceElement e = (new Throwable()).getStackTrace()[back]; if (e.isNativeMethod()) { return " [<native>]"; } return " [" + e.getClassName().split("\\$")[0].replace('.', '/') + ".java:" + e.getLineNumber() + "]"; } catch (ArrayIndexOutOfBoundsException e) { } catch (SecurityException e) { } return " [<unknown>]"; }
From source file:com.ikon.util.StackTraceUtils.java
/** * Return the method who make the call.// w w w. ja va 2 s. co m */ public static void logTrace(Logger log) { // The constructor for Throwable has a native function that fills the stack trace. StackTraceElement[] trace = (new Throwable()).getStackTrace(); // Once you have the trace you can pick out information you need. if (trace.length >= 2) { for (int i = 2; i < trace.length; i++) { if (trace[i].getClassName().startsWith("com.ikon")) { StackTraceElement sse = trace[i]; log.warn("{} -> {} ({}:{})", new Object[] { sse.getClassName(), sse.getMethodName(), sse.getFileName(), sse.getLineNumber() }); } } } }
From source file:com.openkm.util.StackTraceUtils.java
/** * Return the method who make the call.//w w w .j ava 2s . com */ public static void logTrace(Logger log) { // The constructor for Throwable has a native function that fills the stack trace. StackTraceElement[] trace = (new Throwable()).getStackTrace(); // Once you have the trace you can pick out information you need. if (trace.length >= 2) { for (int i = 2; i < trace.length; i++) { if (trace[i].getClassName().startsWith("com.openkm")) { StackTraceElement sse = trace[i]; log.warn("{} -> {} ({}:{})", new Object[] { sse.getClassName(), sse.getMethodName(), sse.getFileName(), sse.getLineNumber() }); } } } }
From source file:Main.java
private static String generateTag(StackTraceElement caller) { String tag = "%s.%s(L:%d)"; String callerClazzName = caller.getClassName(); callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1); tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber()); tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag; return tag;/*from w ww. j av a 2 s . c o m*/ }