List of usage examples for java.lang StackTraceElement getMethodName
public String getMethodName()
From source file:jp.co.opentone.bsol.framework.web.view.action.ActionHandler.java
private void logServiceAbortException(ServiceAbortException e) { StackTraceElement[] elem = e.getStackTrace(); if (elem != null && elem.length > 0) { try {// w w w .ja v a 2s . co m StackTraceElement element = elem[0]; String format = "%s.%s:%d [%s]"; log.warn(String.format(format, getSimpleClassName(element.getClassName()), element.getMethodName(), element.getLineNumber(), e.getMessageCode())); } catch (Exception ex) { log.error(ex.getMessage(), ex); } } }
From source file:org.kuali.rice.krad.uif.util.CopyUtils.java
/** * Mix-in copy implementation for objects that implement the {@link Copyable} interface} * // www . j a v a 2s. c o m * @param <T> copyable type * @param obj The object to copy. * @return A deep copy of the object. */ @SuppressWarnings("unchecked") public static <T> T copy(Copyable obj) { if (obj == null) { return null; } String cid = null; if (ViewLifecycle.isTrace()) { StackTraceElement[] trace = Thread.currentThread().getStackTrace(); int i = 3; while (ComponentUtils.class.getName().equals(trace[i].getClassName())) i++; StackTraceElement caller = trace[i]; cid = obj.getClass().getSimpleName() + ":" + caller.getClassName() + ":" + caller.getMethodName() + ":" + caller.getLineNumber(); ProcessLogger.ntrace("deep-copy:", ":" + cid, 1000L, 500L); } return (T) getDeepCopy(obj); }
From source file:com.dianping.dpsf.jmx.DpsfResponsorMonitor.java
private String getThreadStackTraces(RequestProcessor requestProcessor, State state, int threadCount) { ThreadGroup threadGroup = requestProcessor.getThreadPool().getFactory().getGroup(); Thread[] threads = new Thread[threadGroup.activeCount()]; threadGroup.enumerate(threads, false); StringBuilder builder = new StringBuilder(); int count = 0; if (threads != null && threads.length > 0 && threadCount > 0) { for (Thread thread : threads) { if (state == thread.getState()) { count++;/* w w w . j a v a 2 s . c o m*/ if (count > 1) { builder.append("\r\n\r\n"); } builder.append("Thread ").append(thread.getId()).append(" ").append(thread.getName()) .append(" (state = ").append(state).append(")").append("\r\n"); StackTraceElement[] stackTrace = thread.getStackTrace(); for (StackTraceElement ste : stackTrace) { builder.append(ste.getClassName()).append("-").append(ste.getMethodName()).append("(") .append(ste.getLineNumber()).append(")").append("\r\n"); } if (count >= threadCount) { break; } } } } return builder.toString(); }
From source file:com.ibm.sbt.test.lib.MockSerializer.java
private String getResource() { StackTraceElement trace = getStackTraceElement(); String methodName = trace.getMethodName(); String fullClassName = trace.getClassName().replace(".", "/"); String packageName = fullClassName.substring(0, fullClassName.lastIndexOf("/")); String className = fullClassName.substring(fullClassName.lastIndexOf("/")); String resource = new StringBuilder("/").append(packageName).append("/").append("mockData").append("/") .append(endpointName).append(className).append("_").append(methodName).append(".mock").toString(); return resource; }
From source file:com.stackify.log.log4j2.LogEventAdapter.java
/** * @see com.stackify.api.common.log.EventAdapter#getStackifyError(java.lang.Object, java.lang.Throwable) */// w ww. j a v a2 s . c o m @Override public StackifyError getStackifyError(final LogEvent event, final Throwable exception) { StackifyError.Builder builder = StackifyError.newBuilder(); builder.environmentDetail(envDetail); builder.occurredEpochMillis(new Date(event.getTimeMillis())); if (exception != null) { builder.error(Throwables.toErrorItem(getMessage(event), exception)); } else { String className = null; String methodName = null; int lineNumber = 0; StackTraceElement source = event.getSource(); if (source != null) { className = source.getClassName(); methodName = source.getMethodName(); try { lineNumber = source.getLineNumber(); } catch (Throwable e) { } } builder.error(Throwables.toErrorItem(getMessage(event), className, methodName, lineNumber)); } String user = APMLogData.isLinked() ? APMLogData.getUser() : ServletLogContext.getUser(); if (user != null) { builder.userName(user); } WebRequestDetail webRequest = APMLogData.isLinked() ? APMLogData.getWebRequest() : ServletLogContext.getWebRequest(); if (webRequest != null) { builder.webRequestDetail(webRequest); } builder.serverVariables(Maps.fromProperties(System.getProperties())); return builder.build(); }
From source file:org.universAAL.samples.lighting.client.test.LightingRegularIT.java
/** * Helper method for logging./* w w w . ja v a 2 s . c om*/ * * @param msg */ protected void logInfo(String format, Object... args) { StackTraceElement callingMethod = Thread.currentThread().getStackTrace()[2]; LogUtils.logInfo(Activator.mc, getClass(), callingMethod.getMethodName(), new Object[] { formatMsg(format, args) }, null); }
From source file:org.universAAL.samples.lighting.client.test.LightingRegularIT.java
/** * Helper method for logging./*from www . j a v a2 s . c o m*/ * * @param msg */ protected void logError(Throwable t, String format, Object... args) { StackTraceElement callingMethod = Thread.currentThread().getStackTrace()[2]; LogUtils.logError(Activator.mc, getClass(), callingMethod.getMethodName(), new Object[] { formatMsg(format, args) }, t); }
From source file:com.saucelabs.sauce_ondemand.driver.SauceOnDemandSPIImpl.java
/** * Try to find the name of the test as best we can. *///from ww w. ja v a 2s . c om public String getJobName() { // look for the caller of SeleniumFactory StackTraceElement[] trace = Thread.currentThread().getStackTrace(); boolean foundFactory = false; String callerName = null; for (StackTraceElement e : trace) { if (foundFactory) callerName = e.getClassName() + "." + e.getMethodName(); foundFactory = e.getClassName().equals(SeleniumFactory.class.getName()); } return callerName; }
From source file:org.apromore.service.pql.impl.PQLServiceImpl.java
public List<String> runAPQLQuery(String queryPQL, List<String> IDs, String userID) { //Set<String> idNets=new HashSet<>(); List<String> results = Collections.emptyList(); IPQLAPI api = pqlBean.getApi();/*from w w w . ja v a 2s .com*/ LOGGER.error("-----------PQLAPI: " + api); LOGGER.error("----------- query: " + queryPQL); LOGGER.error("----------- IDs: " + IDs); LOGGER.error("----------- user: " + userID); try { PQLQueryResult pqlQueryResult = api.query(queryPQL, new HashSet<>(IDs)); if (pqlQueryResult.getNumberOfParseErrors() != 0) { results = pqlQueryResult.getParseErrorMessages(); } else {//risultati LOGGER.error("-----------IDS PQLServiceImpl" + IDs); map = pqlQueryResult.getTaskMap(); LinkedList<PQLTask> tasks = new LinkedList<>(map.values()); /* idNets=new HashSet<>(IDs); idNets=api.checkLastQuery(idNets); results.addAll(idNets); */ results = new LinkedList<>(pqlQueryResult.getSearchResults()); LOGGER.error("-----------QUERYAPQL ESATTA " + results); } } catch (Exception e) { LOGGER.error("-----------ERRORRE: " + e.toString()); for (StackTraceElement ste : e.getStackTrace()) LOGGER.info("ERRORE6: " + ste.getClassName() + " " + ste.getMethodName() + " " + ste.getLineNumber() + " " + ste.getFileName()); } return results; }
From source file:au.id.wolfe.riak.log4j.RiakAppender.java
/** * builds the JSON string containing the log event attributes. * * @param recordKey The key for the record. * @param event log event// w w w. j a v a2s . c o m * @throws JSONException This may be caused by malformed string input. * @return String containing log event serialised to JSON. * @see java.util.logging.XMLFormatter * */ private String buildJson(String recordKey, LoggingEvent event) throws JSONException { JSONStringer jsonLogEvent; jsonLogEvent = new JSONStringer(); jsonLogEvent.object(); if (event.getLocationInformation() != null) { JSONObject sourceInfo = new JSONObject(); sourceInfo.put("class", event.getLocationInformation().getClassName()); sourceInfo.put("fileName", event.getLocationInformation().getFileName()); sourceInfo.put("lineNumber", event.getLocationInformation().getLineNumber()); sourceInfo.put("methodName", event.getLocationInformation().getMethodName()); jsonLogEvent.key("sourceInfo").value(sourceInfo); } jsonLogEvent.key("class").value(event.getFQNOfLoggerClass()); jsonLogEvent.key("level").value(event.getLevel()); jsonLogEvent.key("message").value(event.getMessage()); // ripple specific information, I don't see any issue including it even if it is not used. jsonLogEvent.key("record_id").value(recordKey); jsonLogEvent.key("_type").value("LogRecord"); if (event.getThrowableInformation() != null) { ThrowableInformation throwableInformation = event.getThrowableInformation(); JSONArray stack = new JSONArray(); for (StackTraceElement stackTraceElement : throwableInformation.getThrowable().getStackTrace()) { JSONObject frame = new JSONObject(); frame.put("class", stackTraceElement.getClassName()); frame.put("method", stackTraceElement.getMethodName()); if (stackTraceElement.getLineNumber() >= 0) { frame.put("lineNumber", stackTraceElement.getLineNumber()); } stack.put(frame); } JSONObject throwableInfo = new JSONObject(); throwableInfo.put("throwable", throwableInformation.getThrowable().getClass().getCanonicalName()); throwableInfo.put("message", throwableInformation.getThrowable().getMessage()); throwableInfo.put("stack", stack); jsonLogEvent.key("throwableInfo").value(throwableInfo); } jsonLogEvent.key("millis").value(event.getTimeStamp()); return jsonLogEvent.endObject().toString(); }