List of usage examples for java.lang StackTraceElement getClassName
public String getClassName()
From source file:com.simiacryptus.util.lang.CodeUtil.java
/** * Find file file./* w w w. j a va2 s .c o m*/ * * @param callingFrame the calling frame * @return the file */ @javax.annotation.Nonnull public static File findFile(@javax.annotation.Nonnull final StackTraceElement callingFrame) { @javax.annotation.Nonnull final String[] packagePath = callingFrame.getClassName().split("\\."); @javax.annotation.Nonnull final String path = Arrays.stream(packagePath).limit(packagePath.length - 1) .collect(Collectors.joining(File.separator)) + File.separator + callingFrame.getFileName(); return com.simiacryptus.util.lang.CodeUtil.findFile(path); }
From source file:com.linkedin.whiteelephant.mapreduce.lib.job.StagedOutputJob.java
private static Class<?> getCallersClass() { StackTraceElement[] stack = Thread.currentThread().getStackTrace(); boolean foundSelf = false; for (StackTraceElement element : stack) { if (foundSelf && !StagedOutputJob.class.getName().equals(element.getClassName())) { try { return Class.forName(element.getClassName()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); }/*from w w w .j a v a2s . c om*/ } else if (StagedOutputJob.class.getName().equals(element.getClassName()) && "getCallersClass".equals(element.getMethodName())) { foundSelf = true; } } return StagedOutputJob.class; }
From source file:Main.java
public static String getLogInfo(StackTraceElement stackTraceElement) { StringBuilder logInfoStringBuilder = new StringBuilder(); String threadName = Thread.currentThread().getName(); long threadID = Thread.currentThread().getId(); String fileName = stackTraceElement.getFileName(); String className = stackTraceElement.getClassName(); String methodName = stackTraceElement.getMethodName(); int lineNumber = stackTraceElement.getLineNumber(); logInfoStringBuilder.append("[ "); logInfoStringBuilder.append("threadID=" + threadID).append(SEPARATOR); logInfoStringBuilder.append("threadName=" + threadName).append(SEPARATOR); logInfoStringBuilder.append("fileName=" + fileName).append(SEPARATOR); logInfoStringBuilder.append("className=" + className).append(SEPARATOR); logInfoStringBuilder.append("methodName=" + methodName).append(SEPARATOR); logInfoStringBuilder.append("lineNumber=" + lineNumber); logInfoStringBuilder.append(" ] "); return logInfoStringBuilder.toString(); }
From source file:org.apache.tajo.exception.ErrorUtil.java
public static Stacktrace.StackTrace convertStacktrace(Throwable t) { Stacktrace.StackTrace.Builder builder = Stacktrace.StackTrace.newBuilder(); if (t != null) { for (StackTraceElement element : t.getStackTrace()) { builder.addElement(Stacktrace.StackTrace.Element.newBuilder() .setFilename(element.getFileName() == null ? "(Unknown Source)" : element.getFileName()) .setFunction(element.getClassName() + "::" + element.getMethodName()) .setLine(element.getLineNumber())); }//from w w w.j a va2 s . co m } return builder.build(); }
From source file:io.stallion.services.Log.java
public static void warning(String message, Object... args) { if (getLogLevel().intValue() > Level.WARNING.intValue()) { return;/*from w w w . ja v a 2 s .c o m*/ } Throwable t = new Throwable(); StackTraceElement stackTraceElement = t.getStackTrace()[1]; String clz = stackTraceElement.getClassName().replace("io.stallion.", ""); String method = stackTraceElement.getMethodName() + ":" + t.getStackTrace()[1].getLineNumber(); logger.logp(Level.WARNING, clz, method, message, args); }
From source file:io.stallion.services.Log.java
public static void warn(String message, Object... args) { if (getLogLevel().intValue() > Level.WARNING.intValue()) { return;// w w w . j a v a 2 s .c o m } Throwable t = new Throwable(); StackTraceElement stackTraceElement = t.getStackTrace()[1]; String clz = stackTraceElement.getClassName().replace("io.stallion.", ""); String method = stackTraceElement.getMethodName() + ":" + t.getStackTrace()[1].getLineNumber(); logger.logp(Level.WARNING, clz, method, message, args); }
From source file:io.stallion.services.Log.java
public static void warn(Throwable ex, String message, Object... args) { if (getLogLevel().intValue() > Level.WARNING.intValue()) { return;/*from w w w .ja v a 2 s. c o m*/ } if (args.length > 0) { message = MessageFormat.format(message, args); } Throwable t = new Throwable(); StackTraceElement stackTraceElement = t.getStackTrace()[1]; String clz = stackTraceElement.getClassName().replace("io.stallion.", ""); String method = stackTraceElement.getMethodName() + ":" + t.getStackTrace()[1].getLineNumber(); logger.logp(Level.WARNING, clz, method, message, ex); }
From source file:io.stallion.services.Log.java
/** * Logs a message, setting the class, method and source line number using the stack frame index passed in. * This is useful if you are wrapping a logging class, and want to include the line number from where * the wrapper method is called./*from ww w . ja v a 2 s .com*/ * * @param frame - the stack frame to use. Use '2' to log to one level above the caller * @param level * @param message * @param args */ public static void logForFrame(int frame, Level level, String message, Object... args) { if (getLogLevel().intValue() > level.intValue()) { return; } Throwable t = new Throwable(); StackTraceElement stackTraceElement = t.getStackTrace()[frame]; String clz = stackTraceElement.getClassName().replace("io.stallion.", ""); String method = stackTraceElement.getMethodName() + ":" + t.getStackTrace()[frame].getLineNumber(); logger.logp(level, clz, method, message, args); }
From source file:io.stallion.services.Log.java
public static void exception(Throwable ex, String message, Object... args) { HealthTracker.instance().logException(ex); if (getLogLevel().intValue() > Level.SEVERE.intValue()) { return;//from ww w . j ava 2 s .c o m } if (args.length > 0) { message = MessageFormat.format(message, args); } // TODO: WTF -- figure out how the hell the handler got removed; if (logger.getHandlers().length == 0) { logger.addHandler(handler); } Throwable t = new Throwable(); StackTraceElement stackTraceElement = t.getStackTrace()[1]; String clz = stackTraceElement.getClassName().replace("io.stallion.", ""); String method = stackTraceElement.getMethodName() + ":" + t.getStackTrace()[1].getLineNumber(); logger.logp(Level.SEVERE, clz, method, message, ex); }
From source file:org.glowroot.agent.impl.BytecodeServiceImpl.java
private static boolean ignoreMainClass(String expectedTopLevelClass, String expectedTopLevelMethodName, StackTraceElement[] stackTrace) { if (stackTrace.length == 0) { return true; }//from www.j ava 2s . c om StackTraceElement topStackTraceElement = stackTrace[stackTrace.length - 1]; return !topStackTraceElement.getClassName().equals(expectedTopLevelClass) || !expectedTopLevelMethodName.equals(topStackTraceElement.getMethodName()); }