List of usage examples for java.lang StackTraceElement getClassName
public String getClassName()
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 + ')'); }/*from www .ja v a 2 s .com*/ }
From source file:com.hellofyc.base.net.http.HttpUtils.java
private static void getInvokeStackTraceElement() { FLog.i("Thread ID: " + Thread.currentThread().getId() + " getInvokeStackTraceElement"); StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); for (StackTraceElement element : stackTraceElements) { FLog.i("(" + element.getLineNumber() + ") " + "class name:" + element.getClassName() + ", method name:" + element.getMethodName()); }//from w w w .ja va 2s . co m }
From source file:org.apache.samza.logging.log4j2.serializers.LoggingEventJsonSerde.java
/** * Encodes a LoggingEvent into a HashMap using the logstash JSON format. * * @param loggingEvent/*from w ww.j a v a2s . c om*/ * The LoggingEvent to encode. * @param includeLocationInfo * Whether to include LocationInfo in the map, or not. * @return A Map representing the LoggingEvent, which is suitable to be * serialized by a JSON encoder such as Jackson. */ @SuppressWarnings("rawtypes") public static Map<String, Object> encodeToMap(LogEvent loggingEvent, boolean includeLocationInfo) { Map<String, Object> logstashEvent = new LoggingEventJsonSerde.LoggingEventMap(); String threadName = loggingEvent.getThreadName(); long timestamp = loggingEvent.getTimeMillis(); HashMap<String, Object> exceptionInformation = new HashMap<String, Object>(); Map mdc = loggingEvent.getContextData().toMap(); ThreadContext.ContextStack ndc = loggingEvent.getContextStack(); logstashEvent.put("@version", VERSION); logstashEvent.put("@timestamp", dateFormat(timestamp)); logstashEvent.put("source_host", getHostname()); logstashEvent.put("message", loggingEvent.getMessage()); if (loggingEvent.getThrown() != null) { final Throwable throwableInformation = loggingEvent.getThrown(); if (throwableInformation.getClass().getCanonicalName() != null) { exceptionInformation.put("exception_class", throwableInformation.getClass().getCanonicalName()); } if (throwableInformation.getMessage() != null) { exceptionInformation.put("exception_message", throwableInformation.getMessage()); } if (throwableInformation.getMessage() != null) { StringBuilder stackTrace = new StringBuilder(ExceptionUtils.getStackTrace(throwableInformation)); exceptionInformation.put("stacktrace", stackTrace); } logstashEvent.put("exception", exceptionInformation); } if (includeLocationInfo) { StackTraceElement info = loggingEvent.getSource(); logstashEvent.put("file", info.getFileName()); logstashEvent.put("line_number", info.getLineNumber()); logstashEvent.put("class", info.getClassName()); logstashEvent.put("method", info.getMethodName()); } logstashEvent.put("logger_name", loggingEvent.getLoggerName()); logstashEvent.put("mdc", mdc); logstashEvent.put("ndc", ndc); logstashEvent.put("level", loggingEvent.getLevel().toString()); logstashEvent.put("thread_name", threadName); return logstashEvent; }
From source file:com.googlecode.flyway.commandline.Main.java
/** * Output class, method and line number infos of first stack trace element * of the given {@link Throwable} using {@link Log#error(Object)}. * * @param t {@link Throwable} to log/*from w w w . jav a 2s. c o m*/ */ private static void outputFirstStackTraceElement(Throwable t) { StackTraceElement firstStackTraceElement = t.getStackTrace()[0]; LOG.error("Occured in " + firstStackTraceElement.getClassName() + "." + firstStackTraceElement.getMethodName() + "() at line " + firstStackTraceElement.getLineNumber()); }
From source file:org.apache.hadoop.mapred.JettyBugMonitor.java
/** * @return true if the given thread ID appears to be a Jetty selector thread * based on its stack trace//from ww w.ja v a2 s. co m */ private static boolean isJettySelectorThread(long tid) { ThreadInfo info = threadBean.getThreadInfo(tid, 20); for (StackTraceElement stack : info.getStackTrace()) { // compare class names instead of classses, since // jetty uses a different classloader if (SelectChannelConnector.class.getName().equals(stack.getClassName())) { LOG.debug("Thread #" + tid + " (" + info.getThreadName() + ") " + "is a Jetty selector thread."); return true; } } LOG.debug("Thread #" + tid + " (" + info.getThreadName() + ") " + "is not a jetty thread"); return false; }
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()); }// w w w.ja v a 2 s.c o m Log.e("Exception", message.toString(), ex); Log4JHelper.getLogger(context.getPackageName()).error("Exception", ex); Helper.createToast(context, ex.getLocalizedMessage(), false); }
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 w ww .j av a 2 s . c om*/ 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(); }
From source file:controllers.GWT2Controller.java
public static void invoke(String module, String service) throws Exception { // find the module GWT2Module mod = GWT2Plugin.getModule(module, service); if (mod == null) notFound("module not found !"); if (mod.service == null) throw new NullArgumentException("module.service is null"); // create service instance GWT2Service gwtService;/*ww w . ja v a 2 s .c o m*/ try { gwtService = (GWT2Service) mod.service.newInstance(); if (!GWT2Service.class.isAssignableFrom(mod.service)) throw new Exception("module.service is not GWT2Service instance"); } catch (Exception e) { StackTraceElement element = PlayException.getInterestingStrackTraceElement(e); if (element != null) { throw new JavaExecutionException(Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber(), e); } throw new JavaExecutionException(e); } // decode rpc request RPCRequest rpcRequest = RPC.decodeRequest(IO.readContentAsString(request.body), gwtService.getClass(), gwtService); // response load String responseload = null; // check GWT2ServiceAsync GWT2ServiceAsync gwt2AsyncCall = mod.service.getAnnotation(GWT2ServiceAsync.class); if (gwt2AsyncCall != null && gwt2AsyncCall.value()) { // async invokation responseload = invokeAsync(gwtService, rpcRequest); } else { // synced invokation // bt service can use GWT2Chain to do async job responseload = invoke(gwtService, rpcRequest); } renderText(responseload); }
From source file:de.micromata.genome.util.runtime.AssertUtils.java
/** * Gets the code line.//from ww w . ja va 2s . com * * @param se the se * @return the code line */ public static String getCodeLine(final StackTraceElement se) { if (se == null) { return "<stack not found>"; } final String fname = se.getFileName(); final int cl = se.getLineNumber(); final String clsName = se.getClassName(); final String codeLine = getCodeLine(clsName, fname, cl); return StringUtils.trim(codeLine); }
From source file:org.tranche.logs.LogUtil.java
/** * Helper method to log an exception to the Tranche error log. * @param e/*w w w . ja v a 2 s .c om*/ * @param description * @param uzf */ public static void logError(Set<Exception> exceptions, String description, UserZipFile uzf) { // skip all errors originating from JUnit for (Exception e : exceptions) { StackTraceElement[] stes = e.getStackTrace(); for (StackTraceElement ste : stes) { if (ste.getClassName().equals("junit.framework.TestCase")) { return; } } } final StringBuffer descriptionBuffer = new StringBuffer(), exceptionBuffer = new StringBuffer(), userBuffer = new StringBuffer(); // Build: messageBuffer if (description != null && !description.trim().equals("")) { descriptionBuffer.append(description); } else { descriptionBuffer.append(""); } // Build: exceptionBuffer exceptionBuffer.append("Exceptions: " + exceptions.size() + " exceptions to report" + "\n"); for (Exception e : exceptions) { exceptionBuffer.append(e.getClass().getName() + ": " + e.getMessage() + "\n"); for (StackTraceElement ste : e.getStackTrace()) { exceptionBuffer.append(" " + ste + "\n"); } exceptionBuffer.append("\n"); } exceptionBuffer.append("\n"); // Build: userBuffer if (uzf == null) { userBuffer.append(""); } else { userBuffer.append(uzf.getUserNameFromCert() + " <" + uzf.getEmail() + ">"); } final String serversDump = getServersDump(); final String threadDump = getThreadDump(); final String memoryDump = getEnvironmentDump(); final String submitURL = ConfigureTranche.get(ConfigureTranche.CATEGORY_LOGGING, ConfigureTranche.PROP_LOG_ERROR_URL); if (submitURL != null && !submitURL.trim().equals("")) { Thread t = new Thread("Submit error thread") { @Override public void run() { HttpClient c = new HttpClient(); PostMethod pm = new PostMethod(submitURL); try { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new NameValuePair("Exception", exceptionBuffer.toString())); pairs.add(new NameValuePair("Servers", serversDump)); pairs.add(new NameValuePair("Threads", threadDump)); pairs.add(new NameValuePair("Memory", memoryDump)); pairs.add(new NameValuePair("UserInfo", userBuffer.toString())); pairs.add(new NameValuePair("UserComment", descriptionBuffer.toString())); // create the pair array NameValuePair[] pairArray = new NameValuePair[pairs.size()]; for (int i = 0; i < pairs.size(); i++) { pairArray[i] = pairs.get(i); } // set the values pm.setRequestBody(pairArray); // execute the method int statusCode = c.executeMethod(pm); // If registrar failed to send email, do so here... if (statusCode < 200 || statusCode >= 300) { throw new Exception("Failed to register, returned HTTP status code: " + statusCode); } } catch (Exception e) { e.printStackTrace(); } finally { pm.releaseConnection(); } } }; t.start(); } // Send all the information to the appropriate email addresses if (ConfigureTranche.getAdminEmailAccounts().length > 0) { File tempFile = null; try { String subject = "[" + ConfigureTranche.get(ConfigureTranche.CATEGORY_GENERAL, ConfigureTranche.PROP_NAME) + "] Error @ " + TextUtil.getFormattedDate(TimeUtil.getTrancheTimestamp()); StringBuffer msg = new StringBuffer(); msg.append("User comments:\n"); msg.append(descriptionBuffer + "\n\n\n"); msg.append("Submitted by: " + userBuffer + "\n\n\n"); msg.append(exceptionBuffer + "\n"); tempFile = getTroubleshootingInformationFile(); try { EmailUtil.sendEmailHttp(subject, ConfigureTranche.getAdminEmailAccounts(), msg.toString(), tempFile); } catch (Exception ee) { ee.printStackTrace(); } } finally { IOUtil.safeDelete(tempFile); } } }