List of usage examples for java.lang Throwable Throwable
public Throwable()
From source file:edu.umn.msi.tropix.common.logging.ExceptionUtilsTest.java
public <T extends Throwable> void logTest(final boolean message, final Class<T> exceptionClass, final Types type) throws T { final Throwable t = new Throwable(); final String messageStr = "Message"; if (message) { this.log.warn(messageStr); }/* w w w . j ava 2s. co m*/ this.log.info("Exception Info : ", t); EasyMock.replay(this.log); try { if (type.equals(Types.LOG_QUIETLY)) { if (!message) { ExceptionUtils.logQuietly(this.log, t); } else { ExceptionUtils.logQuietly(this.log, t, "Message"); } } else if (type.equals(Types.LOG_AND_CONVERT)) { if (!message && exceptionClass == null) { assert RuntimeException.class.isInstance(ExceptionUtils.logAndConvert(this.log, t)); } else if (exceptionClass == null) { assert RuntimeException.class.isInstance(ExceptionUtils.logAndConvert(this.log, t, messageStr)); } else if (message) { assert exceptionClass .isInstance(ExceptionUtils.logAndConvert(this.log, t, messageStr, exceptionClass)); } else { assert exceptionClass.isInstance(ExceptionUtils.logAndConvert(this.log, t, exceptionClass)); } } else if (type.equals(Types.LOG_AND_RETHROW)) { if (!message && exceptionClass == null) { ExceptionUtils.logAndRethrowUnchecked(this.log, t); } else if (exceptionClass == null) { ExceptionUtils.logAndRethrowUnchecked(this.log, t, messageStr); } else if (message) { ExceptionUtils.logAndRethrow(this.log, t, messageStr, exceptionClass); } else { ExceptionUtils.logAndRethrow(this.log, t, exceptionClass); } } } finally { EasyMock.verify(this.log); } }
From source file:org.eclipse.vjet.dsf.common.trace.DefaultTracer.java
public void exitMethod(final Object caller, final ExitStatus status) { if (!m_traceEnabled) { return;// w w w . j a va2 s. c o m } if (caller == null) { return; } final Throwable t = new Throwable(); t.fillInStackTrace(); final String clsName = getClassName(caller); final String methodName = getMethodName(caller, t); dispatch(new WriterInvoker() { public void process(ITraceWriter w) { w.handleExitMethod(m_traceDepth, clsName, methodName, status); } }); pop(clsName + DOT + methodName); }
From source file:io.stallion.services.Log.java
public static void finer(String message, Object... args) { if (getLogLevel().intValue() > Level.FINER.intValue()) { return;/* www. jav a 2 s . c o m*/ } //System.out.println(message); Throwable t = new Throwable(); t.getStackTrace()[2].toString(); String clz = t.getStackTrace()[2].getClassName().replace("io.stallion.", ""); String method = t.getStackTrace()[2].getMethodName(); logger.logp(Level.FINER, clz, method, message, args); }
From source file:comm.lib.downloader.log.Log.java
/** * Building Message/*from w ww . j a v a 2s . c o m*/ * * @param msg The message you would like logged. * @return Message String */ protected static String buildMessage(TYPE type, String tag, String msg, Throwable thr) { //set the default log path if (TextUtils.isEmpty(path)) { setPath(logDirPath, logFileBaseName, logFileSuffix); } StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2]; boolean isLog2File = false; switch (policy) { case LOG_NONE_TO_FILE: isLog2File = false; break; case LOG_WARN_TO_FILE: if (type == TYPE.WARN) { isLog2File = true; } else { isLog2File = false; } break; case LOG_ERROR_TO_FILE: if (type == TYPE.ERROR) { isLog2File = true; } else { isLog2File = false; } break; case LOG_ALL_TO_FILE: isLog2File = true; break; default: break; } //The log will be shown in logcat. StringBuffer bufferlog = new StringBuffer(); bufferlog.append(caller.getClassName()); bufferlog.append("."); bufferlog.append(caller.getMethodName()); bufferlog.append("( "); bufferlog.append(caller.getFileName()); bufferlog.append(": "); bufferlog.append(caller.getLineNumber()); bufferlog.append(") "); bufferlog.append(System.getProperty("line.separator")); bufferlog.append(msg); if (thr != null) { bufferlog.append(System.getProperty("line.separator")); bufferlog.append(android.util.Log.getStackTraceString(thr)); } if (isLog2File) { //The log will be written in the log file. StringBuffer filelog = new StringBuffer(); filelog.append(type.name()); filelog.append(" "); filelog.append(tag); filelog.append(" "); filelog.append(bufferlog); Log2File.log2file(path, filelog.toString()); } return bufferlog.toString(); }
From source file:org.apache.ranger.service.RangerBaseModelService.java
@SuppressWarnings("unchecked") public RangerBaseModelService() { Class klass = getClass();/*from ww w.j a v a2 s . c o m*/ ParameterizedType genericSuperclass = (ParameterizedType) klass.getGenericSuperclass(); TypeVariable<Class<?>> var[] = klass.getTypeParameters(); if (genericSuperclass.getActualTypeArguments()[0] instanceof Class) { tEntityClass = (Class<T>) genericSuperclass.getActualTypeArguments()[0]; tViewClass = (Class<V>) genericSuperclass.getActualTypeArguments()[1]; } else if (var.length > 0) { tEntityClass = (Class<T>) var[0].getBounds()[0]; tViewClass = (Class<V>) var[1].getBounds()[0]; } else { LOG.fatal("Cannot find class for template", new Throwable()); } if (tEntityClass != null) { tClassName = tEntityClass.getName(); } populateExistingBaseFields = false; countQueryStr = "SELECT COUNT(obj) FROM " + tClassName + " obj "; queryStr = "SELECT obj FROM " + tClassName + " obj "; }
From source file:es.bsc.servicess.ide.Logger.java
/** * Write ERROR type logs/*from w w w. ja v a2 s.c o m*/ * @param message Message */ public void error(String message) { if (level >= ERROR_LEVEL) { StackTraceElement invoker = new Throwable().fillInStackTrace().getStackTrace()[1]; log.log(new Status(Status.ERROR, Activator.PLUGIN_ID, printInvocationInfo(invoker) + " " + message)); } }
From source file:com.heliosapm.opentsdb.client.jvmjmx.custom.aggregation.AggregateFunction.java
/** * Returns the AggregateFunction for the passed name. Applies trim and toUpper to the name first. * @param name The name of the function/*from ww w. ja v a2 s . co m*/ * @return the named AggregateFunction */ public static AggregateFunction forName(CharSequence name) { if (name == null) throw new IllegalArgumentException("The passed AggregateFunction name was null", new Throwable()); try { return AggregateFunction.valueOf(name.toString().trim().toUpperCase()); } catch (Exception e) { throw new IllegalArgumentException( "The passed AggregateFunction name [" + name + "] is not a valid function name", new Throwable()); } }
From source file:org.helios.ember.sftp.SFTPSessionFactory.java
/** * <p>Authenticates the passed principal and returns a <i>root</i> sftp file object in accordance with the factory configuration.</p> * <p><b>CAUTION! :</b> This app passes around SSH passwords and private key passphrases which you should NEVER do. It's just a demo until I figure out a better way to do this.<p> * //from ww w.ja v a 2s . c om * @param sessionLogin The principal * @param landingDirectory The optional landing directory that the returned <i>root</i> sftp file object will represent. Defaults to the principal's home directory * @return the <i>root</i> sftp file object */ public FileObject newSFTPSession(SessionLogin sessionLogin, String landingDirectory) { if (sessionLogin == null) throw new IllegalArgumentException("The passed principal was null", new Throwable()); landingDirectory = cleanLandingDirectory(landingDirectory); //String sessionUri = String.format(sftpUrl, sessionLogin.getName(), sessionLogin.getHost(), sessionLogin.getPort(), landingDirectory); String sessionUri = String.format(sftpUrl, sessionLogin.getName(), sessionLogin.getHost(), landingDirectory); log.info("Building session for [" + sessionUri + "]"); FileSystemOptions fsOptions = new FileSystemOptions(); PrincipalProvidedSessionSftpFileSystemConfigBuilder builder = PrincipalProvidedSessionSftpFileSystemConfigBuilder .getInstance(); try { //builder.setUserDirIsRoot(fsOptions, landingDirectory.trim().isEmpty()); builder.setUserDirIsRoot(fsOptions, true); builder.setRootURI(fsOptions, sessionUri); builder.setSession(fsOptions, sessionLogin.getSession()); return fileSystemManager.resolveFile(sessionUri, fsOptions); } catch (FileSystemException fse) { throw new RuntimeException("VFS FileSystem Exception", fse); } catch (Exception ex) { throw new RuntimeException("Unexpected Exception", ex); } }
From source file:org.eclipse.vjet.dsf.common.trace.handler.TraceConsoleHandler.java
private void traceEnterMethod(TraceEvent event) { final Throwable t = new Throwable(); t.fillInStackTrace();//from www .jav a2 s . c o m Object caller = event.getSource(); final String clsName = TraceUtil.getClassName(caller); final String methodName = TraceUtil.getMethodName(caller, t); push(clsName + DOT + methodName); write(getPadding(m_traceDepth) + ENTER_COLON + clsName + DOT + methodName); // m_xmlWriter.handleEnterMethod(m_traceDepth, clsName, methodName); // m_xmlWriter.writeStartElement(clsName); // m_xmlWriter.writeAttribute(ATTR_METHOD, methodName); // Object[] args = event.getArgs(); // if (args == null || args.length == 0){ // return; // } // // for (Object obj: args){ // m_xmlWriter.writeAttribute("param", TraceUtil.getType(obj)); // } }
From source file:com.taobao.itest.spring.aop.LogInterceptor.java
public Object invoke(MethodInvocation invocation) throws Throwable { Object object = invocation.getThis(); Method method = invocation.getMethod(); Object[] args = invocation.getArguments(); if (!log.isDebugEnabled() || !matches(method.getName())) return invocation.proceed(); StackTraceElement[] stes = new Throwable().getStackTrace(); StackTraceElement testSte = null; for (int i = 0; i < stes.length; i++) { if (stes[i].getClassName().endsWith("Test")) { testSte = stes[i];//from w w w . j a va2 s.co m break; } } if (testSte == null) return invocation.proceed(); boolean isTestMethod = testSte.getMethodName().startsWith("test"); if (testSte == null || !isTestMethod) return invocation.proceed(); String callerClassSimpleName = testSte.getClassName() .substring(testSte.getClassName().lastIndexOf(".") + 1); if (!callerClassSimpleName.endsWith("Test")) return invocation.proceed(); String callerMethodName = testSte.getMethodName(); int lineNumber = testSte.getLineNumber(); String callerInfo = callerClassSimpleName + "." + callerMethodName + (lineNumber >= 0 ? "(" + lineNumber + ")" : "(Unknown Source)"); String invokeClassSimpleName = ClassUtils.getShortClassName(object.getClass()); String invokeInfo = invokeClassSimpleName + "." + method.getName(); String baseInfo = callerInfo + " |" + invokeInfo + " "; if (logInvokeParams) { log.debug(baseInfo + " invoked with params:"); for (int i = 0; i < args.length; i++) { log.debug("param " + (i + 1) + ": "); println(args[i]); } } Object result = null; try { result = invocation.proceed(); } catch (Exception e) { log.debug(baseInfo + " throw exception: "); log.debug(e.getMessage()); throw e; } if (logInvokeResult) { log.debug(baseInfo + " invoked result is: "); println(result); } return result; }