/** * Gets the caller stack trace of the method or constructor which calls it. * * @param excluded * a list of filters which should be not considered as caller * @return the caller stack trace * @since 1.4.2 (17.05.2014) */ public static StackTraceElement[] getCallerStackTrace(final Pattern... excluded) { return getCallerStackTrace(excluded, new Class<?>[0]); }
/** * Gets the caller stack trace of the method or constructor which calls it. * * @return the caller stack trace * @since 1.4.2 (17.05.2014) */ public static StackTraceElement[] getCallerStackTrace() { return getCallerStackTrace(new Pattern[0]); }
/** * Gets the caller class by examing the stacktrace. * * @param excludedMethods * the excluded methods * @param excludedClasses * the excluded classes * @return the caller class */ public static Class<?> getCallerClass(final Pattern[] excludedMethods, final Class<?>... excludedClasses) { StackTraceElement[] stackTrace = getCallerStackTrace(excludedMethods, excludedClasses); String classname = stackTrace[0].getClassName(); try { return Class.forName(classname); } catch (ClassNotFoundException ex) { throw new NotFoundException(classname, ex); } }
/** * Stops the given 'mon' and logs the given command with the needed time if * debug is enabled. * * @param mon * the mon * @param command * the command * @param returnValue * the return value */ public static void stop(final ProfileMonitor mon, final String command, final Object returnValue) { mon.stop(); if (LOG.isDebugEnabled()) { String msg = '"' + command + "\" returned with " + Converter.toShortString(returnValue) + " after " + mon.getLastTime(); if (LOG.isTraceEnabled()) { StackTraceElement[] stacktrace = StackTraceScanner.getCallerStackTrace(new Pattern[0], SqlStatistic.class, StasiStatement.class, StasiPreparedStatement.class); LOG.trace("{}\n\t{}", msg, Converter.toLongString(stacktrace).trim()); } else { LOG.debug("{}.", msg); } } }