Example usage for java.util.logging LogRecord getThrown

List of usage examples for java.util.logging LogRecord getThrown

Introduction

In this page you can find the example usage for java.util.logging LogRecord getThrown.

Prototype

public Throwable getThrown() 

Source Link

Document

Get any throwable associated with the log record.

Usage

From source file:net.oneandone.sushi.fs.webdav.WebdavFilesystem.java

public static void wireLog(String file) {
    Handler handler;// w w w  . j  a  va 2 s.  c  o  m

    WIRE.setLevel(Level.FINE);
    try {
        handler = new FileHandler(file, false);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    handler.setFormatter(new Formatter() {
        @Override
        public String format(LogRecord record) {
            String message;
            Throwable e;
            StringBuilder result;

            message = record.getMessage();
            result = new StringBuilder(message.length() + 1);
            result.append(message);
            result.append('\n');
            e = record.getThrown();
            if (e != null) {
                // TODO getStacktrace(e, result);
            }
            return result.toString();
        }
    });

    WIRE.addHandler(handler);
}

From source file:com.l2jfree.util.logging.L2RuntimeLogFormatter.java

protected final void appendThrown(LogRecord record, TextBuilder tb) {
    Throwable throwable = record.getThrown();

    if (throwable == null) {
        if (record.getLevel().intValue() >= L2AutoInitialization.EXTENDED_LOG_LEVEL.intValue())
            throwable = new ExtendedLog();
        else if (record.getMessage() != null
                && record.getMessage().contains("Unevenly distributed hash code - Degraded Preformance"))
            throwable = new ExtendedLog();
    }//from w  ww.ja va2s  .co  m

    if (throwable != null) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);

            throwable.printStackTrace(pw);

            appendNewline(tb);
            tb.append(sw);
        } finally {
            IOUtils.closeQuietly(pw);
            IOUtils.closeQuietly(sw);
        }
    }
}

From source file:cz.lbenda.coursing.client.GlobalExceptionHandler.java

@Override
public void publish(LogRecord record) {
    boolean noCredential = false;
    Throwable tw = record.getThrown();
    while (tw != null) {
        LOG.trace("tw", tw);
        if (tw instanceof AuthenticationCredentialsNotFoundException) {
            noCredential = true;//from www.ja v a2s . co  m
        }
        tw = tw.getCause();
    }
    if (noCredential) {
        LOG.debug("noCredential");
        LoginForm.showLoginDialog();
        /*
        LoginDialog dialog = new LoginDialog(WindowManager.getDefault().getMainWindow(), true);
        dialog.setVisible(true);
                */
    } else if (record.getThrown() != null) {
        newFunctionActionListener.setLogRecord(record);
        // TODO show dialog
    }
}

From source file:com.p000ison.dev.simpleclans2.dataserver.ServerLoggerHandler.java

@Override
public Formatter getFormatter() {
    return new Formatter() {

        @Override/* w  w  w .  j a va2s.co  m*/
        public String format(LogRecord record) {
            String message = DATE_FORMAT.format(record.getMillis()) + " [" + record.getLevel().toString() + "] "
                    + record.getMessage() + "\n";
            if (record.getThrown() != null) {
                message += ExceptionUtils.getStackTrace(record.getThrown()) + '\n';
            }
            return message;
        }
    };
}

From source file:com.l2jfree.util.logging.L2RuntimeLogFormatter.java

@Override
protected final void format0(LogRecord record, TextBuilder tb) {
    tb.append(record.getLevel()).append(" ");

    appendDate(record, tb);/*from ww w .j av  a2 s .com*/

    if (record.getLevel().intValue() > Level.INFO.intValue() || record.getThrown() != null)
        if (!StringUtils.isEmpty(record.getSourceClassName())
                && !StringUtils.isEmpty(record.getSourceMethodName()))
            tb.append(record.getSourceClassName()).append(".").append(record.getSourceMethodName())
                    .append("(): ");

    appendMessage(record, tb);
    appendThrown(record, tb);
}

From source file:ductive.log.JDKToCommonsHandler.java

@Override
public void publish(LogRecord record) {
    String name = record.getLoggerName();

    Log log = logs.get(name);//from w  ww .j  av a  2  s .  c  om
    if (log == null)
        logs.put(name, log = LogFactory.getLog(name));

    String message = record.getMessage();
    Throwable ex = record.getThrown();
    Level level = record.getLevel();

    if (Level.SEVERE == level)
        log.error(message, ex);
    else if (Level.WARNING == level)
        log.warn(message, ex);
    else if (Level.INFO == level)
        log.info(message, ex);
    else if (Level.CONFIG == level)
        log.debug(message, ex);
    else
        log.trace(message, ex);
}

From source file:joachimeichborn.geotag.logging.LongLogFormat.java

@Override
public String format(final LogRecord aRecord) {
    final StringBuilder sb = new StringBuilder();
    sb.append(new DateTime(aRecord.getMillis()).toString());
    sb.append(" [").append(aRecord.getLevel().getName().charAt(0)).append("] ");
    sb.append(aRecord.getMessage());/*from w w w  . j a  va  2  s.co  m*/
    sb.append(" <").append(aRecord.getLoggerName()).append(">");
    sb.append(System.lineSeparator());
    if (aRecord.getThrown() != null) {
        sb.append(ExceptionUtils.getStackTrace(aRecord.getThrown()));
    }
    return sb.toString();
}

From source file:at.bitfire.davdroid.log.PlainTextFormatter.java

@Override
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public String format(LogRecord r) {
    StringBuilder builder = new StringBuilder();

    if (!logcat)//from   w  w  w  .j  a  va2 s  .c  o m
        builder.append(DateFormatUtils.format(r.getMillis(), "yyyy-MM-dd HH:mm:ss")).append(" ")
                .append(r.getThreadID()).append(" ");

    builder.append(String.format("[%s] %s", shortClassName(r.getSourceClassName()), r.getMessage()));

    if (r.getThrown() != null)
        builder.append("\nEXCEPTION ").append(ExceptionUtils.getStackTrace(r.getThrown()));

    if (r.getParameters() != null) {
        int idx = 1;
        for (Object param : r.getParameters())
            builder.append("\n\tPARAMETER #").append(idx++).append(" = ").append(param);
    }

    if (!logcat)
        builder.append("\n");

    return builder.toString();
}

From source file:hudson.plugins.active_directory.docker.TheFlintstonesTest.java

private List<String> captureLogMessages(int size) {
    final List<String> logMessages = new ArrayList<>(size);
    Logger logger = Logger.getLogger("");
    logger.setLevel(Level.ALL);/*from  w  w w  .jav  a  2  s  .co  m*/

    RingBufferLogHandler ringHandler = new RingBufferLogHandler(size) {

        final Formatter f = new SimpleFormatter(); // placeholder instance for what should have been a static method perhaps

        @Override
        public synchronized void publish(LogRecord record) {
            super.publish(record);
            String message = f.formatMessage(record);
            Throwable x = record.getThrown();
            logMessages.add(message == null && x != null ? x.toString() : message);
        }
    };
    logger.addHandler(ringHandler);

    return logMessages;
}

From source file:ch.jamiete.hilda.LogFormat.java

@Override
public String format(final LogRecord record) {
    String log = "";

    log += this.sdf.format(new Date(record.getMillis()));
    log += " [" + record.getLevel().getLocalizedName().toUpperCase() + "]";

    if (record.getSourceClassName() != null) {
        final String[] split = record.getSourceClassName().split("\\.");
        log += " [" + split[split.length == 1 ? 0 : split.length - 1] + "]";
    }//from  ww  w  .  j  a  v  a2s.  com

    log += " " + record.getMessage();

    if (record.getThrown() != null) {
        log += System.getProperty("line.separator") + ExceptionUtils.getStackTrace(record.getThrown());
    }

    log += System.getProperty("line.separator");

    return log;
}