List of usage examples for java.lang StackTraceElement getFileName
public String getFileName()
From source file:org.gradle.api.GradleScriptException.java
/** * Returns the line in the script where this exception occurred, if known. * * @return The line number, or null if not known. *//*from w w w . j ava2 s . c o m*/ public Integer getLineNumber() { if (lineNumber != null) return lineNumber; // wasn't explicitly set, so search for the line number Integer foundLineNumber = null; String scriptFileName = scriptSource.getFileName(); for (Throwable currentException = this; currentException != null; currentException = currentException .getCause()) { for (StackTraceElement element : currentException.getStackTrace()) { if (scriptFileName.equals(element.getFileName()) && element.getLineNumber() >= 0) { foundLineNumber = element.getLineNumber(); break; } } } return foundLineNumber; }
From source file:es.bsc.servicess.ide.Logger.java
private String printInvocationInfo(StackTraceElement invoker) { return "[" + invoker.getClassName() + "." + invoker.getMethodName() + "(" + invoker.getFileName() + ":" + invoker.getLineNumber() + ")]"; }
From source file:com.cloud.utils.db.Transaction.java
protected static String buildName() { if (s_logger.isDebugEnabled()) { final StackTraceElement[] stacks = Thread.currentThread().getStackTrace(); final StringBuilder str = new StringBuilder(); int i = 3, j = 3; while (j < 15 && i < stacks.length) { StackTraceElement element = stacks[i]; String filename = element.getFileName(); String method = element.getMethodName(); if ((filename != null && filename.equals("<generated>")) || (method != null && method.equals("invokeSuper"))) { i++;/*from w w w . j ava 2 s.co m*/ continue; } str.append("-") .append(stacks[i].getClassName().substring(stacks[i].getClassName().lastIndexOf(".") + 1)) .append(".").append(stacks[i].getMethodName()).append(":") .append(stacks[i].getLineNumber()); j++; i++; } return str.toString(); } return ""; }
From source file:com.lazy.gank.logging.Logcat.java
/** * @param stackTraceElement/*from ww w. j av 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:org.codehaus.groovy.grails.exceptions.DefaultStackTraceFilterer.java
private List<StackTraceElement> filterTraceWithCutOff(StackTraceElement[] trace, String endPackage) { List<StackTraceElement> newTrace = new ArrayList<StackTraceElement>(); boolean foundGroovy = false; for (StackTraceElement stackTraceElement : trace) { String className = stackTraceElement.getClassName(); String fileName = stackTraceElement.getFileName(); if (!foundGroovy && fileName != null && fileName.endsWith(".groovy")) { foundGroovy = true;/*from ww w. ja v a 2s . c o m*/ } if (endPackage != null && className.startsWith(endPackage) && foundGroovy) break; if (isApplicationClass(className)) { if (stackTraceElement.getLineNumber() > -1) { newTrace.add(stackTraceElement); } } } return newTrace; }
From source file:edu.cornell.mannlib.vitro.webapp.utils.developer.loggers.StackTraceUtility.java
public String format(boolean requested) { StringBuilder sb = new StringBuilder(); if (requested) { for (StackTraceElement ste : stackTrace) { sb.append(String.format(" %s.%s(%s:%d) \n", ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber())); }/*from w w w . j a v a2 s. c om*/ sb.append(" ...\n"); } return sb.toString(); }
From source file:airbrake.Backtrace.java
private String toBacktrace(final StackTraceElement element) { return toBacktrace(element.getClassName(), element.getFileName(), element.getLineNumber(), element.getMethodName());//w w w . ja v a 2 s . c o m }
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 . j ava2 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:jext2.JextReentrantReadWriteLock.java
private String[] getElementsThatRequestedLock(StackTraceElement[] stack) { LinkedList<String> interresting = new LinkedList<String>(); for (StackTraceElement element : stack) { if (element.getClassName().contains("jext2") && !element.getClassName().contains("JextReentrantReadWriteLock")) { interresting.add(element.getFileName() + ":" + element.getLineNumber()); }/*from ww w. ja v a 2 s . co m*/ } return interresting.toArray(new String[0]); }
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 w w . ja v a 2 s.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); } }