List of usage examples for java.lang StackTraceElement getLineNumber
public int getLineNumber()
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 w w w . ja va2s .c om*/ } LOG.error("UID=" + uid + ";vmtdn=null/r/n" + sb.toString()); return false; } return true; }
From source file:org.siphon.jssp.JsspRunner.java
public void run(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String requestPath = getServletPath(request); String jsfile = request.getServletContext().getRealPath(requestPath); ScriptObjectMirror d2js = null;/*from w ww . j ava 2s .c o m*/ try { d2js = d2jsManager.getD2js(jsfile, requestPath); if (d2js == null) { response.setStatus(404); PrintWriter out = response.getWriter(); out.print(request.getServletPath() + " not found"); out.flush(); return; } } catch (Exception e3) { logger.error("", e3); throw new ServletException(e3); } JsspRequest jsspRequest = new JsspRequest(request, engine); String params; try { params = getParams(jsspRequest); } catch (Exception e3) { response.setStatus(500); PrintWriter out = response.getWriter(); out.print("params must be json"); out.flush(); return; } JsspWriter out = null; out = new JsspWriter(response, engine); JsspSession session = new JsspSession(request.getSession()); try { ((Invocable) engine).invokeFunction("processJsspRequest", jsfile, params, jsspRequest, response, session, out); } catch (NoSuchMethodException | ScriptException e) { if (out.isDirty()) { response.setStatus(500); for (Throwable throwable = e; throwable != null; throwable = throwable.getCause()) { if (e != throwable) { out.print("<br>Caused By: " + throwable.getMessage() + "<br>"); } else { out.print("<br>" + throwable.getMessage() + "<br>"); } for (StackTraceElement frame : throwable.getStackTrace()) { out.print(" at " + frame.getClassName() + "." + frame.getMethodName() + "(" + frame.getFileName() + ":" + frame.getLineNumber() + ")<br>"); } } } throw new ServletException(e); } }
From source file:net.logstash.logback.encoder.LogstashEncoderV1.java
@Override public void doEncode(ILoggingEvent event) throws IOException { ObjectNode eventNode = MAPPER.createObjectNode(); eventNode.put("@timestamp", ISO_DATETIME_TIME_ZONE_FORMAT_WITH_MILLIS.format(event.getTimeStamp())); eventNode.put("message", event.getFormattedMessage()); eventNode.put("tags", createTags(event)); eventNode.put("thread_name", event.getThreadName()); eventNode.put("logger_name", event.getLoggerName()); eventNode.put("level", event.getLevel().toString()); eventNode.put("level_value", event.getLevel().toInt()); if (isIncludeCallerInfo()) { 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 . c o m IThrowableProxy throwableProxy = event.getThrowableProxy(); if (throwableProxy != null) { eventNode.put("stack_trace", ThrowableProxyUtil.asString(throwableProxy)); } Context context = getContext(); if (context != null) { addPropertiesAsFields(eventNode, context.getCopyOfPropertyMap()); } addPropertiesAsFields(eventNode, event.getMDCPropertyMap()); write(MAPPER.writeValueAsBytes(eventNode), outputStream); write(CoreConstants.LINE_SEPARATOR, outputStream); if (isImmediateFlush()) { outputStream.flush(); } }
From source file:net.ymate.platform.log.jcl.JCLogger.java
/** * ??/*from w w w .j a va 2 s . c o m*/ * * @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:com.bstek.dorado.view.task.LongTaskThread.java
public ExceptionInfo(Exception e) { Throwable throwable = e;/* w w w .jav a 2 s. c om*/ // while (throwable.getCause() != null) { // throwable = throwable.getCause(); // } message = throwable.getMessage(); if (message == null) { message = throwable.getClass().getSimpleName(); } StackTraceElement[] stackTraceElements = throwable.getStackTrace(); stackTrace = new String[stackTraceElements.length]; int i = 0; for (StackTraceElement stackTraceElement : stackTraceElements) { stackTrace[i] = stackTraceElement.getClassName() + '.' + stackTraceElement.getMethodName() + '(' + stackTraceElement.getFileName() + ':' + stackTraceElement.getLineNumber() + ')'; i++; } }
From source file:com.stackify.log.logback.ILoggingEventAdapter.java
/** * @see com.stackify.api.common.log.EventAdapter#getStackifyError(java.lang.Object, java.lang.Throwable) *///w w w .j ava2s . c o m @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.stackify.log.logback.ILoggingEventAdapter.java
/** * @see com.stackify.api.common.log.EventAdapter#getLogMsg(java.lang.Object, com.google.common.base.Optional) *//*w w w .j a v a 2s .c o m*/ @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:com.lazy.gank.logging.Logcat.java
/** * @param stackTraceElement/*w w w . j a v a 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.enonic.cms.web.main.UpgradeController.java
/** * Return the formatted cause./*ww w . ja v a 2 s . c o m*/ */ 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(); }
From source file:org.openflamingo.remote.thrift.thriftfs.ThriftHandlerBase.java
/** * Return a list of threads that currently exist with their stack traces */// ww w. j av a 2 s .c o m public List<ThreadStackTrace> getThreadDump(RequestContext ctx) { List<ThreadStackTrace> dump = new ArrayList<ThreadStackTrace>(); Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces(); for (Map.Entry<Thread, StackTraceElement[]> entry : traces.entrySet()) { final Thread t = entry.getKey(); final StackTraceElement[] frames = entry.getValue(); ThreadStackTrace tst = new ThreadStackTrace(); tst.threadName = t.getName(); tst.threadStringRepresentation = String.valueOf(t); tst.isDaemon = t.isDaemon(); tst.stackTrace = new ArrayList<StackTraceElement>(); for (StackTraceElement ste : frames) { StackTraceElement tFrame = new StackTraceElement(); tFrame.className = ste.getClassName(); tFrame.fileName = ste.getFileName(); tFrame.lineNumber = ste.getLineNumber(); tFrame.methodName = ste.getMethodName(); tFrame.isNativeMethod = ste.isNativeMethod(); tFrame.stringRepresentation = String.valueOf(ste); tst.stackTrace.add(tFrame); } dump.add(tst); } return dump; }