Example usage for java.lang Throwable Throwable

List of usage examples for java.lang Throwable Throwable

Introduction

In this page you can find the example usage for java.lang Throwable Throwable.

Prototype

public Throwable() 

Source Link

Document

Constructs a new throwable with null as its detail message.

Usage

From source file:com.coolstore.common.SLog.java

/**
 * Building Message//from   w w  w  . j a va2s. 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(" : ");
    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:io.kahu.hawaii.util.logger.DefaultLogManager.java

public void storeCaller() {
    StackTraceElement[] trace = new Throwable().getStackTrace();
    int i = 3;/* ww  w .ja v  a 2  s.  c  o  m*/
    boolean skip = true;
    while (skip && i < trace.length) {
        skip = false;
        for (String cls : getLoggingConfiguration().getSkippedLocationClasses()) {
            if (trace[i].getClassName().startsWith(cls)) {
                skip = true;
                i++;
                break;
            }
        }
    }
    if (i < trace.length) {
        String location = trace[i].getClassName() + ":" + trace[i].getLineNumber();
        putContext("log.loc", location);
    }
}

From source file:es.bsc.servicess.ide.Logger.java

public void error(String message, Throwable e) {
    if (level >= ERROR_LEVEL) {
        StackTraceElement invoker = new Throwable().fillInStackTrace().getStackTrace()[1];
        log.log(new Status(Status.ERROR, Activator.PLUGIN_ID, printInvocationInfo(invoker) + " " + message));
        log.log(new Status(Status.ERROR, Activator.PLUGIN_ID, printStackTrace(e)));
    }/* w  ww .  j av a2  s.  c o  m*/
}

From source file:info.magnolia.objectfactory.DefaultComponentProvider.java

@Override
public <T> T newInstance(Class<T> type, Object... parameters) {
    if (type == null) {
        log.error("type can't be null", new Throwable());
        return null;
    }/*from  w  w w .  j ava  2  s. c o m*/

    try {
        if (factories.containsKey(type)) {
            final ComponentFactory<T> factory = (ComponentFactory<T>) factories.get(type);
            return factory.newInstance();
        }

        final String className = getImplementationName(type);
        if (isInRepositoryDefinition(className)) {
            final ComponentConfigurationPath path = new ComponentConfigurationPath(className);
            final ObservedComponentFactory<T> factory = new ObservedComponentFactory<T>(path.getRepository(),
                    path.getPath(), type, this);
            setInstanceFactory(type, factory);
            // now that the factory is registered, we call ourself again
            return newInstance(type);
        }
        final Class<?> clazz = Classes.getClassFactory().forName(className);
        if (!Classes.isConcrete(clazz)) {
            throw new MgnlInstantiationException("No concrete implementation defined for " + clazz);
        }
        final Object instance = Classes.getClassFactory().newInstance(clazz, parameters);

        if (instance instanceof ComponentFactory) {
            final ComponentFactory<T> factory = (ComponentFactory<T>) instance;
            setInstanceFactory(type, factory);
            return factory.newInstance();
        }
        return (T) instance;
    } catch (Exception e) {
        if (e instanceof MgnlInstantiationException) {
            throw (MgnlInstantiationException) e;
        }
        throw new MgnlInstantiationException("Can't instantiate an implementation of this class ["
                + type.getName() + "]: " + ExceptionUtils.getMessage(e), e);
    }
}

From source file:io.stallion.services.Log.java

public static void finest(String message, Object... args) {
    if (getLogLevel().intValue() > Level.FINEST.intValue()) {
        return;// w  w w .ja v a  2s.  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.FINEST, clz, method, message, args);

}

From source file:org.eclipse.vjet.dsf.common.trace.DefaultTracer.java

public void exitMethod(final Object caller, final String msg) {

    if (!m_traceEnabled) {
        return;/* www.j  a  va2s.c om*/
    }

    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, msg);
        }
    });

    pop(clsName + DOT + methodName);
}

From source file:com.architexa.diagrams.relo.parts.ArtifactEditPart.java

public ArtifactFragment getArtifact() {
    Object retVal = getModel();//from   w  w w  .ja v  a 2s .c o  m
    if (retVal instanceof ArtifactFragment) {
        return (ArtifactFragment) retVal;
    } else if (retVal instanceof Artifact) {
        // @tag examine-postRearch: need to re-enable code below and clean things up
        //logger.warn("Got Artifact expecting ArtifactFragment.", new Throwable());
        return new ArtifactFragment((Artifact) retVal);
    } else {
        logger.error("Expecting Artifact got: " + retVal.getClass(), new Throwable());
        return null;
    }
}

From source file:org.eclipse.vjet.dsf.common.trace.handler.DefaultTraceEventHandler.java

private void traceEnterMethod(TraceEvent event) {

    final Throwable t = new Throwable();
    t.fillInStackTrace();//from  w w  w  .  ja  v a  2 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);

    //      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:org.blockfreie.element.hydrogen.murikate.ApplicationUtil.java

public static Map<String, String> prefix() {
    Map<String, String> result = new HashMap<String, String>();
    String classname = new Throwable().getStackTrace()[1].getClassName();
    for (Map.Entry<Object, Object> entry : PROPERTY.entrySet()) {
        if (entry.getKey().toString().startsWith(classname)) {
            String key = entry.getKey().toString();
            String value = entry.getValue().toString();
            LOGGER.log(Level.INFO, String.format("{ key : %s , value : %s }", key, value));
            key = key.substring(classname.length() + 1);
            result.put(key, value);//from w  w  w .j  a va2 s. c o  m
        }
    }
    return result;
}

From source file:io.stallion.services.Log.java

public static void info(String message, Object... args) {
    if (getLogLevel().intValue() > Level.INFO.intValue()) {
        return;/*from  w w w. jav  a  2  s.c om*/
    }
    // Info statements don't include the class and line number, since that kills performance
    //System.out.println(message);
    if (alwaysIncludeLineNumber) {
        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.INFO, clz, method, message, args);
    } else {
        logger.logp(Level.INFO, "", "", message, args);
    }

}