List of usage examples for java.lang StackTraceElement getFileName
public String getFileName()
From source file:com.squarespace.gibson.GibsonUtils.java
private static void append(MessageDigest md, StackTraceElement element) { if (element != null) { append(md, element.getClassName()); append(md, element.getMethodName()); append(md, element.getFileName()); append(md, element.getLineNumber()); }/*from w ww .ja va2s . c om*/ }
From source file:de.domjos.schooltools.helper.Helper.java
public static void printException(Context context, Throwable ex) { StringBuilder message = new StringBuilder(ex.getMessage() + "\n" + ex.toString()); for (StackTraceElement element : ex.getStackTrace()) { message.append(element.getFileName()).append(":").append(element.getClassName()).append(":") .append(element.getMethodName()).append(":").append(element.getLineNumber()); }//from www . j a v a 2 s .com Log.e("Exception", message.toString(), ex); Log4JHelper.getLogger(context.getPackageName()).error("Exception", ex); Helper.createToast(context, ex.getLocalizedMessage(), false); }
From source file:org.apache.flink.api.java.Utils.java
public static String getCallLocationName(int depth) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); if (stackTrace.length < depth) { return "<unknown>"; }// w w w.j a v a 2 s. c o m StackTraceElement elem = stackTrace[depth]; return String.format("%s(%s:%d)", elem.getMethodName(), elem.getFileName(), elem.getLineNumber()); }
From source file:com.cmsz.cloudplatform.utils.StringUtils.java
public static String getExceptionStackInfo(Throwable e) { StringBuffer sb = new StringBuffer(); sb.append(e.toString()).append("\n"); StackTraceElement[] elemnents = e.getStackTrace(); for (StackTraceElement element : elemnents) { sb.append(element.getClassName()).append("."); sb.append(element.getMethodName()).append("("); sb.append(element.getFileName()).append(":"); sb.append(element.getLineNumber()).append(")"); sb.append("\n"); }//from w w w.j a v a 2s. co m return sb.toString(); }
From source file:com.momock.util.Logger.java
static String getSourceInfo(StackTraceElement trace) { return trace.getFileName() + "(" + trace.getLineNumber() + ")"; }
From source file:com.cloud.utils.StringUtils.java
public static String getExceptionStackInfo(final Throwable e) { final StringBuffer sb = new StringBuffer(); sb.append(e.toString()).append("\n"); final StackTraceElement[] elemnents = e.getStackTrace(); for (final StackTraceElement element : elemnents) { sb.append(element.getClassName()).append("."); sb.append(element.getMethodName()).append("("); sb.append(element.getFileName()).append(":"); sb.append(element.getLineNumber()).append(")"); sb.append("\n"); }/*w w w.j a v a 2s. co m*/ return sb.toString(); }
From source file:com.moss.greenshell.wizard.catastrophe.PostMortemScreen.java
public static void submitErrorReport(final Throwable cause, final ErrorReportDecorator... decorators) throws Exception { List<ErrorReportChunk> chunks = new LinkedList<ErrorReportChunk>(); try {/* www.ja va 2 s . co m*/ if (cause instanceof InternalErrorException) { InternalErrorException ie = (InternalErrorException) cause; ErrorReportChunk chunk = new ErrorReportChunk("internal-error-id", "text/plain", ie.id().getBytes("UTF8")); chunks.add(chunk); } else if (cause instanceof SOAPFaultException) { SOAPFaultException soapFault = (SOAPFaultException) cause; String content = soapFault.getFault().getFirstChild().getTextContent(); String prefix = "Internal Service Error Occurred: "; if (content.startsWith(prefix)) { String id = content.substring(prefix.length()); ErrorReportChunk chunk = new ErrorReportChunk("internal-error-id", "text/plain", id.getBytes("UTF8")); chunks.add(chunk); } } } catch (Throwable t) { t.printStackTrace(); } // STACK TRACE ByteArrayOutputStream stackBytes = new ByteArrayOutputStream(); PrintStream stackPrintStream = new PrintStream(stackBytes); cause.printStackTrace(stackPrintStream); stackPrintStream.close(); stackBytes.close(); ErrorReportChunk chunk = new ErrorReportChunk("stack trace", "text/plain", stackBytes.toByteArray()); chunks.add(chunk); // THREAD DUMP ByteArrayOutputStream dumpBytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(dumpBytes); Map<Thread, StackTraceElement[]> traceMap = Thread.getAllStackTraces(); for (Map.Entry<Thread, StackTraceElement[]> next : traceMap.entrySet()) { out.println(); out.println(next.getKey().getName()); for (StackTraceElement line : next.getValue()) { String className = emptyIfNull(line.getClassName()); String methodName = emptyIfNull(line.getMethodName()); String fileName = emptyIfNull(line.getFileName()); out.println(" " + className + "." + methodName + " (" + fileName + " line " + line.getLineNumber() + ")"); } } out.flush(); out.close(); ErrorReportChunk stackDump = new ErrorReportChunk("thread dump", "text/plain", dumpBytes.toByteArray()); chunks.add(stackDump); // SYSTEM PROPERTIES ByteArrayOutputStream propsBytes = new ByteArrayOutputStream(); PrintStream propsOut = new PrintStream(propsBytes); for (Map.Entry<Object, Object> next : System.getProperties().entrySet()) { propsOut.println(" " + next.getKey() + "=" + next.getValue()); } propsOut.flush(); propsOut.close(); chunks.add(new ErrorReportChunk("system properties", "text/plain", propsBytes.toByteArray())); // LOCAL CLOCK chunks.add(new ErrorReportChunk("local clock", "text/plain", new DateTime().toString().getBytes())); // NETWORKING StringBuffer networking = new StringBuffer(); Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); while (ifaces.hasMoreElements()) { NetworkInterface iface = ifaces.nextElement(); networking.append("INTERFACE: " + iface.getName() + " (" + iface.getDisplayName() + ")\n"); Enumeration<InetAddress> addresses = iface.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); networking.append(" Address:" + address.getHostAddress() + "\n"); networking.append(" Cannonical Host Name: " + address.getCanonicalHostName() + "\n"); networking.append(" Host Name: " + address.getHostName() + "\n"); } } chunks.add(new ErrorReportChunk("network configuration", "text/plain", networking.toString().getBytes())); // DECORATORS if (decorators != null) { for (ErrorReportDecorator decorator : decorators) { chunks.addAll(decorator.makeChunks(cause)); } } ErrorReport report = new ErrorReport(chunks); Reporter reporter = new Reporter(); ReportId id = reporter.submitReport(report); }
From source file:com.simiacryptus.util.lang.CodeUtil.java
/** * Find file file.//from w ww. ja va2 s . c o m * * @param callingFrame the calling frame * @return the file */ @javax.annotation.Nonnull public static File findFile(@javax.annotation.Nonnull final StackTraceElement callingFrame) { @javax.annotation.Nonnull final String[] packagePath = callingFrame.getClassName().split("\\."); @javax.annotation.Nonnull final String path = Arrays.stream(packagePath).limit(packagePath.length - 1) .collect(Collectors.joining(File.separator)) + File.separator + callingFrame.getFileName(); return com.simiacryptus.util.lang.CodeUtil.findFile(path); }
From source file:org.ubicompforall.cityexplorer.CityExplorer.java
/*** * Debug method to include the filename, line-number and method of the caller *//*from w w w . j av a 2s . co m*/ public static void debug(int d, String msg) { if (DEBUG >= d) { StackTraceElement[] st = Thread.currentThread().getStackTrace(); int stackLevel = 2; while (stackLevel < st.length - 1 && (st[stackLevel].getMethodName().equals("debug") || st[stackLevel].getMethodName().matches("access\\$\\d+"))) { //|| st[stackLevel].getMethodName().matches("run") stackLevel++; } StackTraceElement e = st[stackLevel]; if (d < 0) { //error Log.e(C, e.getMethodName() + ": " + msg + " at (" + e.getFileName() + ":" + e.getLineNumber() + ")"); } else { //debug Log.d(C, e.getMethodName() + ": " + msg + " at (" + e.getFileName() + ":" + e.getLineNumber() + ")"); } //if debug, else error } // if verbose enough }
From source file:org.kuali.coeus.sys.impl.validation.ErrorReporterImpl.java
public static String getMethodPath(int fromLevel, int toLevel) { StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); //increase the levels to avoid including the method that called this. fromLevel = fromLevel + 1;//from ww w .j av a2 s. co m toLevel = toLevel + 1; if (fromLevel <= 0) { throw new IllegalArgumentException("invalid fromLevel (" + fromLevel + " < 0)"); } if (fromLevel > toLevel) { throw new IllegalArgumentException( "invalid levels (fromLevel " + fromLevel + " > toLevel " + toLevel + ")"); } if (toLevel >= stackTraceElements.length) { throw new IllegalArgumentException( "invalid toLevel (" + toLevel + " >= " + stackTraceElements.length + ")"); } StringBuffer result = new StringBuffer(); int elementIndex = 0; for (StackTraceElement element : stackTraceElements) { if (elementIndex >= fromLevel && elementIndex >= toLevel) { if (result.length() > 0) { result.append(" from "); } result.append(element.getClassName()).append("."); result.append(element.getMethodName()).append("("); result.append(element.getFileName()).append(":"); result.append(element.getLineNumber()).append(")"); } elementIndex++; } return result.toString(); }