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:org.broadleafcommerce.common.logging.Log4JRemoteGwtLoggingService.java

@Override
public String logOnServer(LogRecord record) {

    Level level = record.getLevel();
    String message;/*from   www  . j a  v a2s.  c o m*/
    message = record.getMessage();
    if (Level.INFO.equals(level)) {
        LOG.info(message, record.getThrown());
    } else if (Level.SEVERE.equals(level)) {
        LOG.error(message, record.getThrown());
    } else if (Level.WARNING.equals(level)) {
        LOG.warn(message, record.getThrown());
    } else if (Level.FINE.equals(level)) {
        LOG.debug(message, record.getThrown());
    } else {
        LOG.error(message, record.getThrown());
    }

    return null;
}

From source file:org.broadleafcommerce.common.logging.Log4JRemoteGwtLoggingServlet.java

@Override
public String logOnServer(LogRecord record) {

    Level level = record.getLevel();
    String message;/* www .  j a  v  a 2  s. com*/
    message = getThreadLocalRequest().getRemoteAddr() + ":" + record.getMessage();
    if (Level.INFO.equals(level)) {
        LOG.info(message, record.getThrown());
    } else if (Level.SEVERE.equals(level)) {
        LOG.error(message, record.getThrown());
    } else if (Level.WARNING.equals(level)) {
        LOG.warn(message, record.getThrown());
    } else if (Level.FINE.equals(level)) {
        LOG.debug(message, record.getThrown());
    } else {
        LOG.error(message, record.getThrown());
    }

    return null;
}

From source file:org.diorite.impl.log.ForwardLogHandler.java

@Override
public void publish(final LogRecord record) {
    final Logger logger = this.getLogger(record.getLoggerName());
    final Throwable exception = record.getThrown();
    final Level level = record.getLevel();
    final String message = this.getFormatter().formatMessage(record);
    if (Objects.equals(level, Level.SEVERE)) {
        logger.error(message, exception);
    } else if (Objects.equals(level, Level.WARNING)) {
        logger.warn(message, exception);
    } else if (Objects.equals(level, Level.INFO)) {
        logger.info(message, exception);
    } else if (Objects.equals(level, Level.CONFIG)) {
        logger.debug(message, exception);
    } else {//w  ww. j a v  a 2s  . c om
        logger.trace(message, exception);
    }
}

From source file:org.dstadler.commons.logging.jdk.PatternFormatter.java

@Override
public String format(LogRecord record) {
    Date time = new Date(record.getMillis());
    String formattedTime = dateFormat.format(time);

    final String logMessage;

    if (record.getThrown() == null) {
        Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(),
                record.getSourceClassName(), record.getSourceMethodName() };

        logMessage = logMessageFormat.format(log);
    } else {/*  ww w. j  a  v a2s  .com*/
        String stack = getStackLayout(record.getThrown(), "");

        Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(),
                record.getSourceClassName(), record.getSourceMethodName(), record.getThrown().getMessage(),
                stack };

        logMessage = exceptionMessageFormat.format(log);
    }
    return logMessage;
}

From source file:org.ebayopensource.turmeric.eclipse.core.logging.PluginLogDelegateHandler.java

@Override
public void publish(final LogRecord record) {
    if (record == null || StringUtils.isBlank(record.getMessage()))
        return;//from   w w w.  j av  a 2  s . co  m
    final int level = level(record.getLevel());

    if (shouldLogRawMessage(record)) {
        log(level, record.getLoggerName(), record.getMessage(), null);
    } else {
        log(level, record.getLoggerName(), StringUtils.replace(formatter.format(record), "\n", "\n "),
                record.getThrown());
    }
}

From source file:org.ebayopensource.turmeric.runtime.tests.common.jetty.SimpleConsoleHandler.java

@Override
public void publish(LogRecord record) {
    StringBuilder buf = new StringBuilder();
    buf.append("[").append(record.getLevel().getName());
    buf.append("] ").append(record.getLoggerName());
    buf.append(" (").append(record.getSourceMethodName());
    buf.append("): ").append(record.getMessage());

    System.out.println(buf.toString());
    if (record.getThrown() != null) {
        record.getThrown().printStackTrace(System.out);
    }/*from ww w  .j  a v a  2  s  .c  om*/
}

From source file:org.spoutcraft.launcher.Main.java

@Override
public String format(LogRecord record) {
    StringBuilder builder = new StringBuilder();

    builder.append(date.format(record.getMillis()));
    builder.append(" [");
    builder.append(record.getLevel().getLocalizedName().toUpperCase());
    builder.append("] ");
    builder.append(formatMessage(record));
    builder.append('\n');

    if (record.getThrown() != null) {
        StringWriter writer = new StringWriter();
        record.getThrown().printStackTrace(new PrintWriter(writer));
        builder.append(writer.toString());
    }// w  w w. j  av a2s  .  com

    return builder.toString();
}

From source file:org.syphr.mythtv.test.ConsoleFormatter.java

@Override
public String format(LogRecord record) {
    StringBuilder formattedRecord = new StringBuilder(
            StringUtils.rightPad(record.getSourceClassName(), 65, '.'));
    formattedRecord.append(" | ");

    String message = record.getMessage();
    formattedRecord.append(message != null ? message : " no message provided");
    formattedRecord.append(NEWLINE);/*from   w w  w .j  a  v  a  2 s  .c om*/

    Throwable thrown = record.getThrown();
    if (thrown != null) {
        StringWriter sw = new StringWriter();
        thrown.printStackTrace(new PrintWriter(sw));
        formattedRecord.append(sw);
    }

    return formattedRecord.toString();
}

From source file:tvbrowser.TVBrowser.java

/**
 * Creates a very simple Formatter for log formatting
 *
 * @return a very simple Formatter for log formatting.
 *//*  ww  w.ja  va 2  s.  c o m*/
private static Formatter createFormatter() {
    return new Formatter() {
        public synchronized String format(LogRecord record) {
            StringBuilder sb = new StringBuilder();

            DateFormat mTimeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM);

            String message = formatMessage(record);
            sb.append(mTimeFormat.format(new java.util.Date(System.currentTimeMillis())));
            sb.append(' ');
            sb.append(record.getLevel().getLocalizedName());
            sb.append(": ");
            sb.append(message);
            sb.append('\n');
            if (record.getThrown() != null) {
                try {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    record.getThrown().printStackTrace(pw);
                    pw.close();
                    sb.append(sw.toString());
                } catch (Exception ex) {
                    // ignore
                }
            }
            return sb.toString();
        }
    };
}