List of usage examples for java.lang StackTraceElement getFileName
public String getFileName()
From source file:eu.faircode.adblocker.Util.java
public static void sendCrashReport(Throwable ex, final Context context) { if (!isPlayStoreInstall(context)) return;/* w w w . j a v a2 s . com*/ try { ApplicationErrorReport report = new ApplicationErrorReport(); report.packageName = report.processName = context.getPackageName(); report.time = System.currentTimeMillis(); report.type = ApplicationErrorReport.TYPE_CRASH; report.systemApp = false; ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo(); crash.exceptionClassName = ex.getClass().getSimpleName(); crash.exceptionMessage = ex.getMessage(); StringWriter writer = new StringWriter(); PrintWriter printer = new PrintWriter(writer); ex.printStackTrace(printer); crash.stackTrace = writer.toString(); StackTraceElement stack = ex.getStackTrace()[0]; crash.throwClassName = stack.getClassName(); crash.throwFileName = stack.getFileName(); crash.throwLineNumber = stack.getLineNumber(); crash.throwMethodName = stack.getMethodName(); report.crashInfo = crash; final Intent bug = new Intent(Intent.ACTION_APP_ERROR); bug.putExtra(Intent.EXTRA_BUG_REPORT, report); bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (bug.resolveActivity(context.getPackageManager()) != null) context.startActivity(bug); } catch (Throwable exex) { Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex)); } }
From source file:com.master.metehan.filtereagle.Util.java
public static void sendCrashReport(Throwable ex, final Context context) { if (!isPlayStoreInstall(context)) return;/* w ww .j a va 2 s . c om*/ if (!(Util.isDebuggable(context) || Util.getSelfVersionName(context).contains("beta"))) return; try { ApplicationErrorReport report = new ApplicationErrorReport(); report.packageName = report.processName = context.getPackageName(); report.time = System.currentTimeMillis(); report.type = ApplicationErrorReport.TYPE_CRASH; report.systemApp = false; ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo(); crash.exceptionClassName = ex.getClass().getSimpleName(); crash.exceptionMessage = ex.getMessage(); StringWriter writer = new StringWriter(); PrintWriter printer = new PrintWriter(writer); ex.printStackTrace(printer); crash.stackTrace = writer.toString(); StackTraceElement stack = ex.getStackTrace()[0]; crash.throwClassName = stack.getClassName(); crash.throwFileName = stack.getFileName(); crash.throwLineNumber = stack.getLineNumber(); crash.throwMethodName = stack.getMethodName(); report.crashInfo = crash; final Intent bug = new Intent(Intent.ACTION_APP_ERROR); bug.putExtra(Intent.EXTRA_BUG_REPORT, report); bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (bug.resolveActivity(context.getPackageManager()) != null) context.startActivity(bug); } catch (Throwable exex) { Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex)); } }
From source file:com.chiorichan.factory.ShellFactory.java
public List<ScriptTraceElement> examineStackTrace(StackTraceElement[] stackTrace) { Validate.notNull(stackTrace);/*from w w w. java 2s . co m*/ List<ScriptTraceElement> scriptTrace = Lists.newLinkedList(); for (StackTraceElement ste : stackTrace) { if (ste.getFileName() != null && ste.getFileName().matches("GroovyScript\\d*\\.chi")) { scriptTrace.add(new ScriptTraceElement(ste, scriptHistory.get(ste.getFileName()))); } } return scriptTrace; }
From source file:com.chiorichan.factory.StackFactory.java
public List<ScriptTraceElement> examineStackTrace(StackTraceElement[] stackTrace) { Validate.notNull(stackTrace);/*from ww w . j a v a2s . c om*/ List<ScriptTraceElement> scriptTrace = Lists.newLinkedList(); for (StackTraceElement ste : stackTrace) if (ste.getFileName() != null && scriptStackHistory.containsKey(ste.getFileName())) scriptTrace.add(new ScriptTraceElement(scriptStackHistory.get(ste.getFileName()), ste)); ScriptingContext context = scriptStack.values().toArray(new ScriptingContext[0])[scriptStack.size() - 1]; if (context != null) { boolean contains = false; for (ScriptTraceElement ste : scriptTrace) if (ste.context().filename().equals(context.filename())) contains = true; if (!contains) scriptTrace.add(0, new ScriptTraceElement(context, "")); } return scriptTrace; }
From source file:org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter.java
private void doReportLocation(DeprecatedFeatureUsage usage, StringBuilder target) { List<StackTraceElement> stack = usage.getStack(); if (stack.isEmpty()) { return;//from w w w .j a v a 2 s .com } StackTraceElement directCaller = stack.get(0); if (scripts.containsKey(directCaller.getFileName())) { reportStackTraceElement(directCaller, target); return; } int caller = 1; while (caller < stack.size() && stack.get(caller).getClassName().equals(directCaller.getClassName())) { caller++; } if (caller == stack.size()) { return; } StackTraceElement indirectCaller = stack.get(caller); if (scripts.containsKey(indirectCaller.getFileName())) { reportStackTraceElement(indirectCaller, target); } }
From source file:com.chiorichan.factory.ScriptTraceElement.java
public ScriptTraceElement(ScriptingContext context, StackTraceElement ste) { this.context = context; fileName = ste.getFileName(); methodName = ste.getMethodName();/* w w w .jav a 2 s . co m*/ className = ste.getClassName(); lineNum = ste.getLineNumber(); colNum = -1; }
From source file:com.github.pjungermann.config.specification.dsl.groovy.SpecificationDSLInterpreter.java
protected int getCurrentLine() { for (final StackTraceElement element : new Exception().getStackTrace()) { if (element.getFileName().equals(source.getName())) { return element.getLineNumber(); }//from w ww. j a v a 2s . c om } return -1; }
From source file:org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter.java
private void reportStackTraceElement(StackTraceElement stackTraceElement, StringBuilder target) { ScriptSource scriptSource = scripts.get(stackTraceElement.getFileName()); target.append(StringUtils.capitalize(scriptSource.getDisplayName())); if (stackTraceElement.getLineNumber() > 0) { target.append(": line "); target.append(stackTraceElement.getLineNumber()); }//from w w w . j a va 2s .c om }
From source file:com.lazy.gank.logging.Logcat.java
/** * @param stackTraceElement//from www . j a va 2 s .c o m * @param type * @param objectMsg * @param tagArgs */ private static void printLog(final StackTraceElement stackTraceElement, int type, Object objectMsg, @Nullable String... tagArgs) { String msg; if (m_cLogCatShowLogType == OPERATION_BIT) { return; } String fileName = stackTraceElement.getFileName(); String methodName = stackTraceElement.getMethodName(); int lineNumber = stackTraceElement.getLineNumber(); StringBuilder tagBuilder = new StringBuilder(); tagBuilder.append(TAG); if (tagArgs == null) { tagBuilder.append(TAG_SEPARATOR); tagBuilder.append(fileName); } else { for (String tagArg : tagArgs) { tagBuilder.append(TAG_SEPARATOR); tagBuilder.append(tagArg); } } methodName = methodName.substring(0, 1).toUpperCase() + methodName.substring(1); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("[ (").append(fileName).append(":").append(lineNumber).append(")#").append(methodName) .append(" ] "); if (objectMsg == null) { msg = "Log with null Object"; } else { msg = objectMsg.toString(); } if (msg != null && type != SHOW_JSON_LOG) { stringBuilder.append(msg); } String logStr = stringBuilder.toString(); switch (type) { case SHOW_VERBOSE_LOG: Log.v(tagBuilder.toString(), logStr); break; case SHOW_DEBUG_LOG: Log.d(tagBuilder.toString(), logStr); break; case SHOW_INFO_LOG: Log.i(tagBuilder.toString(), logStr); break; case SHOW_WARN_LOG: Log.w(tagBuilder.toString(), logStr); break; case SHOW_ERROR_LOG: Log.e(tagBuilder.toString(), logStr); break; case SHOW_JSON_LOG: { if (TextUtils.isEmpty(msg)) { Log.d(tagBuilder.toString(), "Empty or Null json content"); return; } String message = null; try { if (msg.startsWith("{")) { JSONObject jsonObject = new JSONObject(msg); message = jsonObject.toString(JSON_INDENT); } else if (msg.startsWith("[")) { JSONArray jsonArray = new JSONArray(msg); message = jsonArray.toString(JSON_INDENT); } } catch (JSONException e) { e("JSONException/" + tagBuilder.toString(), e.getCause().getMessage() + LINE_SEPARATOR + msg); return; } printLine(JSON + tagBuilder.toString(), true); message = logStr + LINE_SEPARATOR + message; String[] lines = message.split(LINE_SEPARATOR); StringBuilder jsonContent = new StringBuilder(); for (String line : lines) { jsonContent.append(" ").append(line).append(LINE_SEPARATOR); } Log.d(JSON + tagBuilder.toString(), jsonContent.toString()); printLine(JSON + tagBuilder.toString(), false); } break; } }
From source file:org.uiautomation.ios.communication.FailedWebDriverLikeResponse.java
private JSONArray serializeStackTrace(StackTraceElement[] els) throws JSONException { JSONArray stacktace = new JSONArray(); for (StackTraceElement el : els) { JSONObject stckEl = new JSONObject(); stckEl.put("fileName", el.getFileName()); stckEl.put("className", el.getClassName()); stckEl.put("methodName", el.getMethodName()); stckEl.put("lineNumber", el.getLineNumber()); stacktace.put(stckEl);//from w w w . j a v a2 s .com } return stacktace; }