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:es.bsc.servicess.ide.Logger.java

/**
 * Write DEBUG type logs/*from ww w .ja v  a 2 s.  c o m*/
 * @param message Message
 */
public void debug(String message) {
    if (level >= DEBUG_LEVEL) {
        StackTraceElement invoker = new Throwable().fillInStackTrace().getStackTrace()[1];
        log.log(new Status(Status.INFO, Activator.PLUGIN_ID, printInvocationInfo(invoker) + " " + message));
    }
}

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

public static void fine(String message, Object... args) {
    if (getLogLevel().intValue() > Level.FINE.intValue()) {
        return;/*from   w  ww  .  j ava 2  s  .  co m*/
    }
    //System.out.println(message);
    if (alwaysIncludeLineNumber) {
        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.FINE, clz, method, message, args);
    } else {
        logger.logp(Level.FINE, "", "", message, args);
    }

}

From source file:com.screenslicer.common.Log.java

public static void info(String message) {
    if (logger == null) {
        init("screenslicer", true);
    }/*from w ww. java 2 s.c om*/
    logger.log(Level.INFO,
            "Message \"" + message + "\" ~ Current stack: " + ExceptionUtils.getStackTrace(new Throwable()));
}

From source file:com.zavakid.mushroom.impl.MetricsSourceAdapter.java

void start() {
    if (mbeanName != null) {
        LOG.warn("MBean Source " + name + " already initialized!");
    }//w w  w.  ja va  2s.  c  om
    mbeanName = MBeans.register(prefix, name, this);
    LOG.info("MBean for source " + name + " registered.");
    LOG.debug("Stacktrace: " + new Throwable());
}

From source file:com.atinternet.tracker.CrashDetectionHandlerTest.java

@Test
public void getClassNameTest() throws Exception {
    assertNotNull(executePrivateMethod(crashDetectionHandler, "getClassNameException",
            new Object[] { new Throwable() }));
}

From source file:jetbrains.exodus.entitystore.Explainer.java

public void start(Object origin) {
    if (origin != null) {
        if (queries.get(origin) == null) {
            Map<String, Object> map = new ConcurrentHashMap<>();
            queries.put(origin, map);/*from  w w w  .j  a  v a2s.c o  m*/
            map.put(INSTANTIATED_FROM, "\nat " + stripStackTrace(new Throwable()));
        } else {
            queries.get(origin).put(CONCURRENT_TRAVERSE_WARNING, "");
        }
    }
}

From source file:org.codehaus.plexus.archiver.tar.TarArchiverTest.java

public void testCreateArchiveWithDetectedModes() throws Exception {

    String[] executablePaths = { "path/to/executable", "path/to/executable.bat" };

    String[] confPaths = { "path/to/etc/file", "path/to/etc/file2" };

    String[] logPaths = { "path/to/logs/log.txt" };

    int exeMode = 0777;
    int confMode = 0600;
    int logMode = 0640;

    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        StackTraceElement e = new Throwable().getStackTrace()[0];
        System.out//from w  w w  . j  av  a  2  s . c om
                .println("Cannot execute test: " + e.getMethodName() + " on " + System.getProperty("os.name"));
        return;
    }

    File tmpDir = null;
    try {
        tmpDir = File.createTempFile("tbz2-with-chmod.", ".dir");
        tmpDir.delete();

        tmpDir.mkdirs();

        for (String executablePath : executablePaths) {
            writeFile(tmpDir, executablePath, exeMode);
        }

        for (String confPath : confPaths) {
            writeFile(tmpDir, confPath, confMode);
        }

        for (String logPath : logPaths) {
            writeFile(tmpDir, logPath, logMode);
        }

        {
            Map attributesByPath = PlexusIoResourceAttributeUtils.getFileAttributesByPath(tmpDir);
            for (String path : executablePaths) {
                PlexusIoResourceAttributes attrs = (PlexusIoResourceAttributes) attributesByPath.get(path);
                if (attrs == null) {
                    attrs = (PlexusIoResourceAttributes) attributesByPath
                            .get(new File(tmpDir, path).getAbsolutePath());
                }

                assertNotNull(attrs);
                assertEquals("Wrong mode for: " + path + "; expected: " + exeMode, exeMode,
                        attrs.getOctalMode());
            }

            for (String path : confPaths) {
                PlexusIoResourceAttributes attrs = (PlexusIoResourceAttributes) attributesByPath.get(path);
                if (attrs == null) {
                    attrs = (PlexusIoResourceAttributes) attributesByPath
                            .get(new File(tmpDir, path).getAbsolutePath());
                }

                assertNotNull(attrs);
                assertEquals("Wrong mode for: " + path + "; expected: " + confMode, confMode,
                        attrs.getOctalMode());
            }

            for (String path : logPaths) {
                PlexusIoResourceAttributes attrs = (PlexusIoResourceAttributes) attributesByPath.get(path);
                if (attrs == null) {
                    attrs = (PlexusIoResourceAttributes) attributesByPath
                            .get(new File(tmpDir, path).getAbsolutePath());
                }

                assertNotNull(attrs);
                assertEquals("Wrong mode for: " + path + "; expected: " + logMode, logMode,
                        attrs.getOctalMode());
            }
        }

        File tarFile = getTestFile("target/output/tar-with-modes.tar");

        TarArchiver archiver = getPosixTarArchiver();
        archiver.setDestFile(tarFile);

        archiver.addDirectory(tmpDir);
        archiver.createArchive();

        assertTrue(tarFile.exists());

        File tarFile2 = getTestFile("target/output/tar-with-modes-L2.tar");

        archiver = getPosixTarArchiver();
        archiver.setDestFile(tarFile2);

        archiver.addArchivedFileSet(tarFile);
        archiver.createArchive();

        TarFile tf = new TarFile(tarFile2);

        Map<String, TarArchiveEntry> entriesByPath = new LinkedHashMap<String, TarArchiveEntry>();
        for (Enumeration e = tf.getEntries(); e.hasMoreElements();) {
            TarArchiveEntry te = (TarArchiveEntry) e.nextElement();
            entriesByPath.put(te.getName(), te);
        }

        for (String path : executablePaths) {
            TarArchiveEntry te = entriesByPath.get(path);

            int mode = te.getMode() & UnixStat.PERM_MASK;

            assertEquals("Wrong mode for: " + path + "; expected: " + exeMode, exeMode, mode);
        }

        for (String path : confPaths) {
            TarArchiveEntry te = entriesByPath.get(path);

            int mode = te.getMode() & UnixStat.PERM_MASK;

            assertEquals("Wrong mode for: " + path + "; expected: " + confMode, confMode, mode);
        }

        for (String path : logPaths) {
            TarArchiveEntry te = entriesByPath.get(path);

            int mode = te.getMode() & UnixStat.PERM_MASK;

            assertEquals("Wrong mode for: " + path + "; expected: " + logMode, logMode, mode);
        }
    } finally {
        if (tmpDir != null && tmpDir.exists()) {
            try {
                FileUtils.forceDelete(tmpDir);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.comcast.video.dawg.cats.ir.IrClientTest.java

@Test
public void testIRKeyException() {
    String msg = "msg";
    KeyException exp = new KeyException(msg);
    Assert.assertEquals(exp.getMessage(), msg);
    exp = new KeyException(new Throwable());
    Assert.assertNotEquals(exp.getMessage(), msg);
}

From source file:org.coconut.core.LoggersTest.java

private void testPrintStream(Logger log, SystemErrOutHelper str) {
    testLevelOn(log, Logger.Level.Trace.getLevel());
    log.trace("trace test a");
    assertTrue(str.last.getLast().indexOf("trace test a") >= 0);

    log.debug("debug test a");
    assertTrue(str.last.getLast().indexOf("debug test a") >= 0);

    log.info("info test a");
    assertTrue(str.last.getLast().indexOf("info test a") >= 0);

    log.warn("warn test a");
    assertTrue(str.last.getLast().indexOf("warn test a") >= 0);

    log.error("error test a");
    assertTrue(str.last.getLast().indexOf("error test a") >= 0);

    log.fatal("fatal test a");
    assertTrue(str.last.getLast().indexOf("fatal") >= 0);

    Throwable t = new Throwable();
    int l = t.getStackTrace().length + 1;
    log.trace("trace test a", t);
    assertTrue(str.getFromLast(l).indexOf("trace test a") >= 0);

    log.debug("debug test a", t);
    assertTrue(str.getFromLast(l).indexOf("debug test a") >= 0);

    log.info("info test a", t);
    assertTrue(str.getFromLast(l).indexOf("info test a") >= 0);

    log.warn("warn test a", t);
    assertTrue(str.getFromLast(l).indexOf("warn test a") >= 0);

    log.error("error test a", t);
    assertTrue(str.getFromLast(l).indexOf("error test a") >= 0);

    log.fatal("fatal test a", t);
    assertTrue(str.getFromLast(l).indexOf("fatal") >= 0);
}

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

/**
 * Write WARNING type logs/* w  ww  . j  a v  a2  s . c o m*/
 * @param message Message
 */
public void warn(String message) {
    if (level >= WARN_LEVEL) {
        StackTraceElement invoker = new Throwable().fillInStackTrace().getStackTrace()[1];
        log.log(new Status(Status.WARNING, Activator.PLUGIN_ID, printInvocationInfo(invoker) + " " + message));
    }
}