List of usage examples for java.lang StackTraceElement getLineNumber
public int getLineNumber()
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++;//from ww w. ja v a 2 s .c om 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.stackify.log.log4j2.LogEventAdapter.java
/** * @see com.stackify.api.common.log.EventAdapter#getStackifyError(java.lang.Object, java.lang.Throwable) *//*from ww w. j ava2 s . com*/ @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.cagrid.identifiers.namingauthority.StressTestUtil.java
public void testOnlyRegisterGSID(SecurityInfo client, long numberOfTests) { List<String> identifiers = new ArrayList<String>(); String suggestedIdentifier = null; int randomNumber; for (long i = 0l; i < numberOfTests; i++) { randomNumber = rand.nextInt(20); String parentIdentifiers[] = null; // 2 parents 5% if (randomNumber == 0 && identifiers.size() > 2) { int firstIdIndex = rand.nextInt(identifiers.size()); int secondIdIndex = rand.nextInt(identifiers.size()); while (secondIdIndex == firstIdIndex) secondIdIndex = rand.nextInt(identifiers.size()); parentIdentifiers = new String[] { identifiers.get(firstIdIndex), identifiers.get(secondIdIndex) }; }//from w ww. j ava2 s . com // 1 parent 25 % else if (identifiers.size() > 0 && randomNumber % 4 == 1) { int firstIdIndex = rand.nextInt(identifiers.size()); parentIdentifiers = new String[] { identifiers.get(firstIdIndex) }; } try { String identifier = testUtil.registerGSID(client, suggestedIdentifier, parentIdentifiers); // if(i%100==0) // System.out.println(i); addElement2List(identifiers, identifier); writeToFile(identifier); } catch (Exception e) { System.out.println("exception occured1 " + e.getMessage()); e.printStackTrace(); StringBuffer sb = new StringBuffer(); for (StackTraceElement temp : e.getStackTrace()) sb.append(temp.getClassName() + "[" + temp.getLineNumber() + "]\n"); log.debug("exception occured \n" + sb.toString()); } } }
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// www . j av a 2 s . co 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(); }
From source file:io.coala.log.CoalaLog4jLogger.java
/** * @return/* w w w . j a v a 2 s. c o m*/ */ protected String getMethodAffix() { int i = 4; StackTraceElement elem = Thread.currentThread().getStackTrace()[i]; while (isLoggingPackage(elem.getClassName())) elem = Thread.currentThread().getStackTrace()[++i]; return String.format(METHOD_AFFIX_FORMAT, elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber()); }
From source file:net.logstash.logback.LogstashFormatter.java
private void createFields(ILoggingEvent event, Context context, ObjectNode eventNode) { final Marker marker = event.getMarker(); eventNode.put("logger_name", event.getLoggerName()); eventNode.put("thread_name", event.getThreadName()); eventNode.put("level", event.getLevel().toString()); eventNode.put("level_value", event.getLevel().toInt()); if (includeCallerInfo) { StackTraceElement callerData = extractCallerData(event); eventNode.put("caller_class_name", callerData.getClassName()); eventNode.put("caller_method_name", callerData.getMethodName()); eventNode.put("caller_file_name", callerData.getFileName()); eventNode.put("caller_line_number", callerData.getLineNumber()); }/*from w ww . ja v a 2 s. co m*/ IThrowableProxy throwableProxy = event.getThrowableProxy(); if (throwableProxy != null) { eventNode.put("stack_trace", ThrowableProxyUtil.asString(throwableProxy)); } if (context != null) { addPropertiesAsFields(eventNode, context.getCopyOfPropertyMap()); } if (marker != null && marker.contains("JSON")) { eventNode.put("json_message", getJsonNode(event)); } addPropertiesAsFields(eventNode, event.getMDCPropertyMap()); addCustomFields(eventNode); }
From source file:org.vulpe.controller.struts.interceptor.VulpeExceptionMappingInterceptor.java
/** * * @param invocation/* ww w . ja va 2 s . c om*/ * @param exception * @return */ protected String treatExceptionMessage(final ActionInvocation invocation, final Throwable exception) { final VulpeStrutsController<?, ?> action = (VulpeStrutsController<?, ?>) invocation.getAction(); final Throwable cause = getCause(exception); String message = cause.getMessage(); String key = exception.getClass().getName(); if (cause instanceof JspException) { key = cause.getClass().getName(); } else if (cause instanceof SQLException) { key = cause.getClass().getName(); } message = action.vulpe.controller().text(key); final String contactAdministratorMessageKey = "vulpe.error.contact.system.administrator"; message += action.vulpe.controller().text(contactAdministratorMessageKey); if (isDebug(action)) { final String errorOccurrenceDebugKey = "vulpe.error.occurrence.debug"; message += action.vulpe.controller().text(errorOccurrenceDebugKey); if (exception instanceof NullPointerException) { final StackTraceElement ste = exception.getStackTrace()[0]; final String fileName = ste.getFileName().replace(".java", ""); final String methodName = ste.getMethodName(); final int lineNumber = ste.getLineNumber(); message += action.vulpe.controller().text(key + ".debug", fileName, methodName, lineNumber); } else { message += "<i>" + (exception instanceof VulpeValidationException ? "entity" : cause.getMessage()) + "</i>"; } } return message; }
From source file:com.bstek.dorado.idesupport.resolver.RobotResolver.java
protected void assembleError(Document document, Element responseElement, Exception error) { String message = error.getMessage(); if (message == null) { message = error.getClass().getSimpleName(); }// w ww . ja va 2s . c om Element messageElement = document.createElement("Message"); messageElement.appendChild(document.createTextNode(message)); responseElement.appendChild(messageElement); Element stackTraceElement = document.createElement("StackTrace"); responseElement.appendChild(stackTraceElement); StackTraceElement[] stackTrace = error.getStackTrace(); for (StackTraceElement ste : stackTrace) { Element element = document.createElement("Element"); element.setAttribute("className", ste.getClassName()); element.setAttribute("methodName", ste.getMethodName()); element.setAttribute("fileName", ste.getFileName()); element.setAttribute("lineNumber", String.valueOf(ste.getLineNumber())); stackTraceElement.appendChild(element); } }
From source file:org.cagrid.identifiers.namingauthority.NamingAuthorityTestCase.java
@Test public void testRegisterGSID() { // System.out.println("testing the RegisterGSID"); LOG.info("testing testRegisterGSID method"); // check no register access. SecurityInfo secInfo = new SecurityInfoImpl("Unknown"); try {/*from www.java 2 s .c om*/ this.NamingAuthority.registerGSID(secInfo, null, null); fail("test registerGSID"); } catch (Exception e) { LOG.info("passed registerGSID for " + secInfo.getUser() + ". MSG:\" " + e.getMessage() + "\""); } secInfo = new SecurityInfoImpl("User13"); try { this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", "443", "SB"); LOG.info("passed registerSite inorder to test registerGSID for user " + secInfo.getUser()); } catch (Exception e) { StringBuffer sb = new StringBuffer(); for (StackTraceElement temp : e.getStackTrace()) sb.append(temp.getClassName() + "[" + temp.getLineNumber() + "]\n"); fail("test registeSite for user " + secInfo.getUser() + ". MSG:\"" + sb.toString() + "\""); } String identifier = null; try { identifier = this.NamingAuthority.registerGSID(secInfo, null, null); LOG.info("passed registerGSID without parent and Identifier for " + secInfo.getUser() + "."); } catch (Exception e) { fail("test registerGSID without parent and Identifier for " + secInfo.getUser() + ". MSG: \"" + e.getMessage() + "\""); } try { this.NamingAuthority.registerGSID(secInfo, null, new String[] { identifier, " ", "" }); LOG.info("passed test registerGSID with parentIdentifiers not null for " + secInfo.getUser() + "."); } catch (Exception e) { fail("test registerGSID with parentIdentifiers not null for " + secInfo.getUser() + ". MSG: \"" + e.getMessage() + "\""); } identifier = "5784d1dd-9373-533e-8086-fd479fbd564e"; try { identifier = this.NamingAuthority.registerGSID(secInfo, identifier, null); LOG.info("passed test registerGSID with suggestedIdentifier not null for " + secInfo.getUser() + ". id: " + identifier); } catch (Exception e) { fail("test registerGSID with suggestedIdentifier not null for " + secInfo.getUser() + ". MSG: \"" + e.getMessage() + "\""); } try { identifier = this.NamingAuthority.registerGSID(secInfo, identifier, new String[] { identifier, " ", "" }); fail("test registerGSID with suggestedIdentifier and parent identifiers as not null and with suggestedIdentifier as one of the member in the parent identifier " + secInfo.getUser()); } catch (Exception e) { LOG.info( "test registerGSID with suggestedIdentifier and parent identifiers as not null and with suggestedIdentifier as one of the member in the parent identifier " + secInfo.getUser()); } }
From source file:com.bstek.dorado.view.resolver.ViewServiceResolver.java
/** * @param jsonBuilder/*from w w w . j ava 2 s. c o m*/ * @param e */ protected void outputException(JsonBuilder jsonBuilder, Throwable throwable) { while (throwable.getCause() != null) { throwable = throwable.getCause(); } String message = throwable.getMessage(); if (message == null) { message = throwable.getClass().getSimpleName(); } try { jsonBuilder.object(); // TODO: ?JSONBuilder? jsonBuilder.key("exceptionType").value("JavaException").key("message").value(message).key("stackTrace"); jsonBuilder.array(); StackTraceElement[] stackTrace = throwable.getStackTrace(); for (StackTraceElement stackTraceElement : stackTrace) { jsonBuilder.value(stackTraceElement.getClassName() + '.' + stackTraceElement.getMethodName() + '(' + stackTraceElement.getFileName() + ':' + stackTraceElement.getLineNumber() + ')'); } jsonBuilder.endArray(); jsonBuilder.endObject(); } catch (Exception e) { // ignore e!!! throwable.printStackTrace(); } }