List of usage examples for java.lang StackTraceElement getMethodName
public String getMethodName()
From source file:org.hillview.utils.HillviewLogger.java
private String createMessage(String message, String format, Object... arguments) { message = this.checkCommas(message); String text = MessageFormat.format(format, arguments); Thread current = Thread.currentThread(); StackTraceElement[] stackTraceElements = current.getStackTrace(); StackTraceElement caller = stackTraceElements[3]; String quoted = this.quote(text); return String.join(",", current.getName(), caller.getClassName(), caller.getMethodName(), message, quoted); }
From source file:com.stackify.log.logback.ILoggingEventAdapter.java
/** * @see com.stackify.api.common.log.EventAdapter#getLogMsg(java.lang.Object, com.google.common.base.Optional) *///from w w w . j a va 2 s . com @Override public LogMsg getLogMsg(final ILoggingEvent event, final StackifyError error) { LogMsg.Builder builder = LogMsg.newBuilder(); builder.msg(event.getFormattedMessage()); Map<String, String> props = event.getMDCPropertyMap(); if (props != null) { if (!props.isEmpty()) { try { builder.data(json.writeValueAsString(props)); } catch (Exception e) { // do nothing } } } builder.ex(error); builder.th(event.getThreadName()); builder.epochMs(event.getTimeStamp()); builder.level(event.getLevel().toString().toLowerCase()); String transactionId = ServletLogContext.getTransactionId(); if (transactionId != null) { builder.transId(transactionId); } StackTraceElement[] callerData = event.getCallerData(); if (callerData != null) { StackTraceElement locInfo = callerData[0]; if (locInfo != null) { builder.srcMethod(locInfo.getClassName() + "." + locInfo.getMethodName()); try { builder.srcLine(locInfo.getLineNumber()); } catch (Throwable e) { } } } return builder.build(); }
From source file:airbrake.Backtrace.java
private String toBacktrace(final StackTraceElement element) { return toBacktrace(element.getClassName(), element.getFileName(), element.getLineNumber(), element.getMethodName()); }
From source file:net.ymate.platform.log.jcl.JCLogger.java
/** * ??/* www.java 2 s . c om*/ * * @return ??className.methodName:lineNumber?NO_STACK_TRACE:-1 */ protected String __doMakeCallerInfo() { StackTraceElement[] _stacks = new Throwable().getStackTrace(); // ??? if (_stacks.length > 3) { StackTraceElement _element = _stacks[3]; return StringUtils.substringBeforeLast(_element.getClassName(), ".").concat(".") .concat(_element.getMethodName()).concat(":") .concat(_element.getLineNumber() + StringUtils.EMPTY); } return "NO_STACK_TRACE:-1"; }
From source file:CheckThreadViolationRepaintManager.java
private void checkThreadViolations(JComponent c) { if (!SwingUtilities.isEventDispatchThread() && (completeCheck || c.isShowing())) { boolean repaint = false; boolean fromSwing = false; boolean imageUpdate = false; StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement st : stackTrace) { if (repaint && st.getClassName().startsWith("javax.swing.")) { fromSwing = true;/* w w w . j av a 2 s .co m*/ } if (repaint && "imageUpdate".equals(st.getMethodName())) { imageUpdate = true; } if ("repaint".equals(st.getMethodName())) { repaint = true; fromSwing = false; } } if (imageUpdate) { // assuming it is java.awt.image.ImageObserver.imageUpdate(...) // image was asynchronously updated, that's ok return; } if (repaint && !fromSwing) { // no problems here, since repaint() is thread safe return; } // ignore the last processed component if (lastComponent != null && c == lastComponent.get()) { return; } lastComponent = new WeakReference<JComponent>(c); violationFound(c, stackTrace); } }
From source file:net.duckling.ddl.service.team.dao.VMTTeamManagerImpl.java
private boolean validateVmtDn(String vmtdn, String uid) { if (StringUtils.isEmpty(vmtdn)) { StackTraceElement[] s = Thread.currentThread().getStackTrace(); StringBuilder sb = new StringBuilder(); if (s != null) { for (StackTraceElement st : s) { sb.append(st.getClassName()); sb.append("."); sb.append(st.getMethodName() + "(), line " + st.getLineNumber()); sb.append("/r/n"); }//from ww w .j ava 2s . co m } LOG.error("UID=" + uid + ";vmtdn=null/r/n" + sb.toString()); return false; } return true; }
From source file:org.apache.geode.internal.net.SSLSocketIntegrationTest.java
@Test public void configureClientSSLSocketCanTimeOut() throws Exception { final Semaphore serverCoordination = new Semaphore(0); // configure a non-SSL server socket. We will connect // a client SSL socket to it and demonstrate that the // handshake times out final ServerSocket serverSocket = new ServerSocket(); serverSocket.bind(new InetSocketAddress(SocketCreator.getLocalHost(), 0)); Thread serverThread = new Thread() { public void run() { serverCoordination.release(); try (Socket clientSocket = serverSocket.accept()) { System.out.println("server thread accepted a connection"); serverCoordination.acquire(); } catch (Exception e) { System.err.println("accept failed"); e.printStackTrace();/*from w w w .j a v a 2s . co m*/ } try { serverSocket.close(); } catch (IOException e) { // ignored } System.out.println("server thread is exiting"); } }; serverThread.setName("SocketCreatorJUnitTest serverSocket thread"); serverThread.setDaemon(true); serverThread.start(); serverCoordination.acquire(); SocketCreator socketCreator = SocketCreatorFactory .getSocketCreatorForComponent(SecurableCommunicationChannel.SERVER); int serverSocketPort = serverSocket.getLocalPort(); try { Awaitility.await("connect to server socket").atMost(30, TimeUnit.SECONDS).until(() -> { try { Socket clientSocket = socketCreator.connectForClient( SocketCreator.getLocalHost().getHostAddress(), serverSocketPort, 2000); clientSocket.close(); System.err.println( "client successfully connected to server but should not have been able to do so"); return false; } catch (SocketTimeoutException e) { // we need to verify that this timed out in the handshake // code System.out.println("client connect attempt timed out - checking stack trace"); StackTraceElement[] trace = e.getStackTrace(); for (StackTraceElement element : trace) { if (element.getMethodName().equals("configureClientSSLSocket")) { System.out.println("client connect attempt timed out in the appropriate method"); return true; } } // it wasn't in the configuration method so we need to try again } catch (IOException e) { // server socket may not be in accept() yet, causing a connection-refused // exception } return false; }); } finally { serverCoordination.release(); } }
From source file:com.lazy.gank.logging.Logcat.java
/** * @param stackTraceElement/* www . java 2 s . co m*/ * @param type * @param objectMsg * @param logFileName * @param tagArgs */ private static void fileLog(StackTraceElement stackTraceElement, int type, Object objectMsg, @Nullable String logFileName, @Nullable String... tagArgs) { String msg; if (m_cFileSaveLogType == OPERATION_BIT) { return; } String fileName = stackTraceElement.getFileName(); String className = stackTraceElement.getClassName(); String methodName = stackTraceElement.getMethodName(); int lineNumber = stackTraceElement.getLineNumber(); StringBuilder tagBuilder = new StringBuilder(); tagBuilder.append(TAG); if (tagArgs == null) { tagBuilder.append(TAG_SEPARATOR); tagBuilder.append(className); } 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(); // ?? String strDateTimeLogHead = simpleDateFormat.format(new Date()); // ????? stringBuilder.append(tagBuilder.toString()).append(" ").append(strDateTimeLogHead).append(LINE_SEPARATOR) .append("fileName:").append(fileName).append(LINE_SEPARATOR).append("className:").append(className) .append(LINE_SEPARATOR).append("methodName:").append(methodName).append(LINE_SEPARATOR) .append("lineNumber:").append(lineNumber).append(LINE_SEPARATOR); if (objectMsg == null) { msg = "Log with null Object"; } else { msg = objectMsg.toString(); } if (msg != null && type != SHOW_JSON_LOG) { stringBuilder.append(msg); } stringBuilder.append(LINE_SEPARATOR + LINE_SEPARATOR); switch (type) { case SHOW_VERBOSE_LOG: if (logFileName == null) { saveLog2File(V + stringBuilder.toString()); } else { saveLog2File(V + stringBuilder.toString(), logFileName); } break; case SHOW_DEBUG_LOG: if (logFileName == null) { saveLog2File(D + stringBuilder.toString()); } else { saveLog2File(D + stringBuilder.toString(), logFileName); } break; case SHOW_INFO_LOG: if (logFileName == null) { saveLog2File(I + stringBuilder.toString()); } else { saveLog2File(I + stringBuilder.toString(), logFileName); } break; case SHOW_WARN_LOG: if (logFileName == null) { saveLog2File(W + stringBuilder.toString()); } else { saveLog2File(W + stringBuilder.toString(), logFileName); } break; case SHOW_ERROR_LOG: if (logFileName == null) { saveLog2File(E + stringBuilder.toString()); } else { saveLog2File(E + stringBuilder.toString(), logFileName); } 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; } stringBuilder.append(JSON); stringBuilder.append(LINE_SEPARATOR); stringBuilder.append( "??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????"); message = stringBuilder.toString() + LINE_SEPARATOR + message; String[] lines = message.split(LINE_SEPARATOR); StringBuilder jsonContent = new StringBuilder(); for (String line : lines) { jsonContent.append(" ").append(line).append(LINE_SEPARATOR); } jsonContent.append( "????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????"); if (logFileName == null) { saveLog2File(jsonContent.toString()); } else { saveLog2File(stringBuilder.toString(), logFileName); } } break; } }
From source file:com.stackify.log.logback.ILoggingEventAdapter.java
/** * @see com.stackify.api.common.log.EventAdapter#getStackifyError(java.lang.Object, java.lang.Throwable) *///w ww . j a v a 2 s . c om @Override public StackifyError getStackifyError(final ILoggingEvent event, final Throwable exception) { StackifyError.Builder builder = StackifyError.newBuilder(); builder.environmentDetail(envDetail); builder.occurredEpochMillis(new Date(event.getTimeStamp())); if (exception != null) { builder.error(Throwables.toErrorItem(event.getFormattedMessage(), exception)); } else { String className = null; String methodName = null; int lineNumber = 0; StackTraceElement[] callerData = event.getCallerData(); if (callerData != null) { StackTraceElement locInfo = callerData[0]; if (locInfo != null) { className = locInfo.getClassName(); methodName = locInfo.getMethodName(); lineNumber = locInfo.getLineNumber(); } } builder.error(Throwables.toErrorItem(event.getFormattedMessage(), className, methodName, lineNumber)); } String user = ServletLogContext.getUser(); if (user != null) { builder.userName(user); } WebRequestDetail webRequest = ServletLogContext.getWebRequest(); if (webRequest != null) { builder.webRequestDetail(webRequest); } builder.serverVariables(Maps.fromProperties(System.getProperties())); return builder.build(); }
From source file:com.enonic.cms.web.main.UpgradeController.java
/** * Return the formatted cause./* w ww . ja v a 2 s . c om*/ */ private String getFormattedCause(Throwable cause) { StringBuffer str = new StringBuffer(); str.append("<div class='stacktrace'>"); for (StackTraceElement elem : cause.getStackTrace()) { str.append("<div class='traceelem'>"); str.append(elem.getClassName()).append(".").append(elem.getMethodName()).append(" (line "); str.append(elem.getLineNumber()).append(")"); str.append("</div>"); } str.append("</div>"); return str.toString(); }