List of usage examples for java.lang StackTraceElement getClassName
public String getClassName()
From source file:org.codelibs.fess.web.base.FessBaseAction.java
protected void buildApplicationExceptionStackTrace(RuntimeException cause, StringBuilder sb) { final StackTraceElement[] stackTrace = cause.getStackTrace(); if (stackTrace == null) { // just in case return;//from w ww . j a va2 s. c o m } int index = 0; for (StackTraceElement element : stackTrace) { if (index > 10) { // not all because it's not error break; } final String className = element.getClassName(); final String fileName = element.getFileName(); // might be null final int lineNumber = element.getLineNumber(); final String methodName = element.getMethodName(); sb.append("\n at ").append(className).append(".").append(methodName); sb.append("(").append(fileName); if (lineNumber >= 0) { sb.append(":").append(lineNumber); } sb.append(")"); ++index; } }
From source file:io.hops.metadata.util.RMUtilities.java
public static String getCallerMethod(String className) { StackTraceElement[] elements = Thread.currentThread().getStackTrace(); StringBuilder sb = new StringBuilder(); sb.append(", caller-"); for (StackTraceElement elem : elements) { if (elem.getClassName().contains(className)) { sb.append(elem.getClassName()); sb.append("-"); sb.append(elem.getMethodName()); }//from ww w. j av a2 s .c o m } return sb.toString(); }
From source file:org.schimpf.util.Logger.java
/** * Almacena el mensaje de una excepcion en el log * /* w ww . jav a 2 s. c om*/ * @author <FONT style='color:#55A; font-size:12px; font-weight:bold;'>Hermann D. Schimpf</FONT> * @author <B>HDS Solutions</B> - <FONT style="font-style:italic;">Soluciónes Informáticas</FONT> * @version Oct 1, 2012 12:55:33 PM * @param level Nivel del mensaje * @param exception Excepcion a mostrar */ public synchronized void log(final Level level, final Throwable exception) { // verificamos si alguno esta habilitado if (!level.isEnabled(this.consoleLevel) && !level.isEnabled(this.fileLevel)) // salimos return; // generamos el inicio del mensaje final String logStart = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") .format(new Date(System.currentTimeMillis())) + " " + StringUtils.rightPad("[" + level.name() + "]", 9) + this.name + " "; // iniciamos el mensaje final StringBuffer log = new StringBuffer(logStart); // agregamos el mensaje de la excepcion log.append(exception.getClass().getName() + (exception.getMessage() != null ? ": " + exception.getMessage() : "")); // recorremos los pasos for (final StackTraceElement stackTrace : exception.getStackTrace()) // agregamos el elemento log.append("\n" + logStart + "\t" + stackTrace.getClassName() + "." + stackTrace.getMethodName() + "(" + stackTrace.getFileName() + ":" + stackTrace.getLineNumber() + ")"); // verificamos si mostramos en consola if (level.isEnabled(this.consoleLevel)) // verificamos si es >= ERROR if (level.isEnabled(Level.ERROR)) // mostrar el mensaje en consola de error System.err.println(log); else // mostrar el mensaje en consola de error System.out.println(log); // verificamos si mostramos en el fichero if (level.isEnabled(this.fileLevel) && this.logToFile) // escribimos la linea en el fichero this.writeToFile(log.toString()); // recorremos los listeners for (final LoggerListener listener : Logger.listeners) // enviamos el mensaje listener.log(this, log.toString(), level, true); }
From source file:com.yourkey.billing.util.InAppBilling.java
private String getErrorLocation(int stackFrame) { StackTraceElement element = new Throwable().getStackTrace()[stackFrame + 1]; String className = element.getClassName(); if (className.startsWith(packageName + ".")) className = className.substring(packageName.length() + 1); return ("Error location: " + element.getFileName() + " (" + Integer.toString(element.getLineNumber()) + ")\n" + className + "." + element.getMethodName()); }
From source file:org.schimpf.util.Logger.java
/** * @author <FONT style='color:#55A; font-size:12px; font-weight:bold;'>Hermann D. Schimpf</FONT> * @author <B>SCHIMPF</B> - <FONT style="font-style:italic;">Sistemas de Información y Gestión</FONT> * @author <B>Schimpf.NET</B> * @version Aug 1, 2012 6:13:53 PM//from w w w . j a v a 2s . co m * @param name Nombre para el logger * @param logFile Ruta al fichero log */ public Logger(final String name, final String logFile) { // generamos una ruta final Throwable caller = new Throwable(); // clase temporal Class<?> tempClass = null; // recorremos la ruta for (final StackTraceElement trace : caller.getStackTrace()) try { // obtenemos el nombre de la clase final Class<?> callerClass = Class.forName(trace.getClassName()); // verificamos si no es la clase Logger if (!callerClass.equals(this.getClass())) // almacenamos la clase tempClass = callerClass; } catch (final ClassNotFoundException ignored) { } // almacenamos la clase this.clazz = tempClass; // almacenamos la clase this.name = name; // verificamos si es una carpeta if (logFile != null && new File(logFile).exists() && new File(logFile).isDirectory()) // el fichero log lo tomamos desde el nombre this.logFile = new File(logFile + FileSystems.getDefault().getSeparator() + this.name + ".log"); else // almacenamos el fichero log this.logFile = new File(logFile != null ? logFile : this.name + ".log"); // verificamos si se especifico el fichero log this.enableLogFile(logFile != null); }
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
@Override public void onTrackerUpdate() { IntentTracker tracker = getIntentEditor().getIntentTracker(); FormattedTextBuilder ftb = new FormattedTextBuilder(); ftb.appendRaw("[Tracking intent]\naction " + (tracker.actionRead() ? "" : "NOT ") + "read"); ftb.appendText("Read extras:"); for (final ReadBundleEntryInfo entryInfo : tracker.getExtrasTracker().getReadEntries()) { ftb.appendClickable(entryInfo.name, new ClickableSpan() { @Override/*www . java 2 s. c o m*/ public void onClick(View widget) { String message = entryInfo.methodName; if (entryInfo.stackTrace != null) { message += "\n\n"; for (StackTraceElement element : entryInfo.stackTrace) { message += element.getClassName() + " " + element.getMethodName() + " " + element.getLineNumber() + "\n"; } } new AlertDialog.Builder(getActivity()).setTitle(entryInfo.name).setMessage(message).show(); } }); } mIntentTrackerSummary.setText(ftb.getText()); mIntentTrackerSummary.setVisibility(View.VISIBLE); }
From source file:org.gbif.dwca.action.ValidateAction.java
private void setMetadataException(Exception e) { metadataException = e;/*from ww w .j a v a 2 s . com*/ for (StackTraceElement el : e.getStackTrace()) { if (el.getClassName().equalsIgnoreCase(this.getClass().getName())) { metadataStackTrace.add(el); break; } metadataStackTrace.add(el); } }
From source file:org.gbif.dwca.action.ValidateAction.java
private void setRecordsException(Exception e) { recordsException = e;/*w ww . j av a2 s . c o m*/ for (StackTraceElement el : e.getStackTrace()) { if (el.getClassName().equalsIgnoreCase(this.getClass().getName())) { recordsStackTrace.add(el); break; } recordsStackTrace.add(el); } }
From source file:org.gbif.dwca.action.ValidateAction.java
private void setDwcaException(Exception e) { valid = false;//from w w w .java 2s .c o m dwcaException = e; for (StackTraceElement el : e.getStackTrace()) { if (el.getClassName().equalsIgnoreCase(this.getClass().getName())) { dwcaStackTrace.add(el); break; } dwcaStackTrace.add(el); } }
From source file:org.gbif.dwca.action.ValidateAction.java
private void setSchemaException(Exception e) { valid = false;/* w w w . ja va2 s. c o m*/ schemaException = e; schemaStackTrace = new ArrayList<StackTraceElement>(); for (StackTraceElement el : e.getStackTrace()) { if (el.getClassName().equalsIgnoreCase(this.getClass().getName())) { schemaStackTrace.add(el); break; } schemaStackTrace.add(el); } }