List of usage examples for java.lang StackTraceElement getFileName
public String getFileName()
From source file:com.momock.util.Logger.java
static String getLog(String level, String msg) { Throwable t = new Throwable(); StackTraceElement trace = t.getStackTrace()[2]; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.ENGLISH); if (remoteLogger != null) { remoteLogger.log(level, msg, trace.getFileName() + "(" + trace.getLineNumber() + ")"); }/* ww w. ja va2 s. c o m*/ return "[" + level + "] " + sdf.format(new Date()) + " in " + trace.getFileName() + "(" + trace.getLineNumber() + ") >" + msg; }
From source file:sf.net.experimaestro.utils.JSUtils.java
/** * @see org.mozilla.javascript.RhinoException#getScriptStack() * @param ex//w ww . jav a2 s . c om * @return A stack */ static public ScriptStackElement[] getScriptStackTrace(Throwable ex) { List<ScriptStackElement> list = new ArrayList<>(); ScriptStackElement[][] interpreterStack = null; int interpreterStackIndex = 0; StackTraceElement[] stack = ex.getStackTrace(); // Pattern to recover function name from java method name - // see Codegen.getBodyMethodName() // kudos to Marc Guillemot for coming up with this Pattern pattern = Pattern.compile("_c_(.*)_\\d+"); for (StackTraceElement e : stack) { String fileName = e.getFileName(); if (e.getMethodName().startsWith("_c_") && e.getLineNumber() > -1 && fileName != null && !fileName.endsWith(".java")) { String methodName = e.getMethodName(); Matcher match = pattern.matcher(methodName); // the method representing the main script is always "_c_script_0" - // at least we hope so methodName = !"_c_script_0".equals(methodName) && match.find() ? match.group(1) : null; list.add(new ScriptStackElement(fileName, methodName, e.getLineNumber())); } else if ("org.mozilla.javascript.Interpreter".equals(e.getClassName()) && "interpretLoop".equals(e.getMethodName()) && interpreterStack != null && interpreterStack.length > interpreterStackIndex) { for (ScriptStackElement elem : interpreterStack[interpreterStackIndex++]) { list.add(elem); } } } return list.toArray(new ScriptStackElement[list.size()]); }
From source file:kilim.Fiber.java
static void ds() { for (StackTraceElement ste : new Exception().getStackTrace()) { String cl = ste.getClassName(); String meth = ste.getMethodName(); if (cl.startsWith("kilim.Worker") || meth.equals("go") || meth.equals("ds")) continue; String line = ste.getLineNumber() < 0 ? "" : ":" + ste.getLineNumber(); log.info('\t' + cl + '.' + ste.getMethodName() + '(' + ste.getFileName() + line + ')'); }//w ww . j av a 2s . c o m }
From source file:com.codepunk.codepunklib.util.log.FormattingLogger.java
/** * Returns the concrete information from the given {@link StackTraceElement} that is represented * by the given Placeholder.// w w w. ja va 2s . c o m * @param element The {@link StackTraceElement}. * @param placeholder The {@link Placeholder} to replace. * @return The information represented by the Placeholder. */ private static Object getFromElement(StackTraceElement element, Placeholder placeholder) { try { switch (placeholder) { case FILE_NAME: return element.getFileName(); case HASH_CODE: return element.hashCode(); case LINE_NUMBER: return element.getLineNumber(); case METHOD_NAME: return element.getMethodName(); case PACKAGE: { return getClass(element).getPackage().getName(); } case CLASS_NAME: case SIMPLE_CLASS_NAME: default: { String name; Class cls = getClass(element); do { if (cls == null) { name = UNKNOWN_CLASS_NAME; } else if (placeholder == Placeholder.CLASS_NAME) { name = cls.getName(); } else { name = cls.getSimpleName(); } } while (TextUtils.isEmpty(name)); return name; } } } catch (ClassNotFoundException e) { return UNKNOWN_CLASS_NAME; } }
From source file:Debug.java
public static String getStackTrace(Throwable e, int limit, int skip) { StringBuffer result = new StringBuffer(); if (e != null) { StackTraceElement stes[] = e.getStackTrace(); if (stes != null) { for (int i = skip; i < stes.length && (limit < 0 || i < limit); i++) { StackTraceElement ste = stes[i]; result.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")" + newline); }// w w w .ja v a2s . c o m if (limit >= 0 && stes.length > limit) result.append("\t..." + newline); } // e.printStackTrace(System.out); result.append(newline); } return result.toString(); }
From source file:org.eclipse.epp.internal.logging.aeri.ui.model.Reports.java
public static Throwable newThrowable(java.lang.Throwable throwable) { Throwable mThrowable = factory.createThrowable(); mThrowable.setMessage(throwable.getMessage()); mThrowable.setClassName(throwable.getClass().getName()); List<StackTraceElement> mStackTrace = mThrowable.getStackTrace(); for (java.lang.StackTraceElement stackTraceElement : throwable.getStackTrace()) { StackTraceElement mStackTraceElement = factory.createStackTraceElement(); mStackTraceElement.setFileName(stackTraceElement.getFileName()); mStackTraceElement.setClassName(ensureNotBlank(stackTraceElement.getClassName(), throwable)); mStackTraceElement.setMethodName(ensureNotBlank(stackTraceElement.getMethodName(), throwable)); mStackTraceElement.setLineNumber(stackTraceElement.getLineNumber()); mStackTraceElement.setNative(stackTraceElement.isNativeMethod()); mStackTrace.add(mStackTraceElement); }/*w w w . ja v a2 s. c om*/ java.lang.Throwable cause = throwable.getCause(); if (cause != null) { if (cause == throwable) { log(WARN_CYCLIC_EXCEPTION, cause.toString()); return mThrowable; } mThrowable.setCause(newThrowable(cause)); } return mThrowable; }
From source file:org.lilyproject.avro.AvroConverter.java
private static AvroStackTraceElement convert(StackTraceElement el) { AvroStackTraceElement result = new AvroStackTraceElement(); result.setClassName(el.getClassName()); result.setMethodName(el.getMethodName()); result.setFileName(el.getFileName()); result.setLineNumber(el.getLineNumber()); return result; }
From source file:com.googlecode.fightinglayoutbugs.helpers.TestHelper.java
private static File findSourceFileFor(StackTraceElement stackTraceElement) { final String className = stackTraceElement.getClassName(); final int i = className.lastIndexOf('.'); final String packageDir = (i == -1 ? "" : "/" + className.substring(0, i).replace('.', '/')); final File workDir = new File(new File("dummy").getAbsolutePath()).getParentFile(); // Maven 2 directory layout ... final String testSourcesDir = "src/test/java"; final String sourceFileName = stackTraceElement.getFileName(); File sourceFile = new File(testSourcesDir + packageDir, sourceFileName); if (!sourceFile.exists()) { System.err.println("Could not find " + sourceFile.getAbsolutePath() + " (current work dir: " + workDir.getAbsolutePath() + ")."); sourceFile = null;// ww w.ja v a 2 s.c o m } return sourceFile; }
From source file:com.att.aro.core.util.Util.java
/** * Returns package.Class::methodName of method enclosing call to this method * /*from w w w. j a v a 2s . c om*/ * @return */ public static String getMethod() { StackTraceElement traceElement = Thread.currentThread().getStackTrace()[2]; String name = null; // traceElement.getClassName() + "::" + traceElement.getMethodName(); name = ((traceElement.getFileName()).split("\\."))[0] + "::" + traceElement.getMethodName() + "(...)"; return name; }
From source file:android_network.hetnet.vpn_service.Util.java
public static void sendCrashReport(Throwable ex, final Context context) { if (!isPlayStoreInstall(context) || Util.isDebuggable(context)) return;// w ww . j av a2 s .c om 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)); } }