Example usage for java.util.logging LogRecord getLevel

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

Introduction

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

Prototype

public Level getLevel() 

Source Link

Document

Get the logging message level, for example Level.SEVERE.

Usage

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

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

        @Override//from  ww w. j a va 2 s . 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.acuityph.commons.logging.SimpleFormatter.java

/**
 * {@inheritDoc}/*from  w  w  w.j  a v  a 2 s.com*/
 *
 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
 */
@Override
public final String format(final LogRecord logRecord) {
    final StringBuilder sb = new StringBuilder();
    sb.append(LEVELS_MAP.get(logRecord.getLevel()));
    final DateFormat sdf = DateFormat.getDateTimeInstance();
    sb.append(sdf.format(new Date(logRecord.getMillis()))).append(' ');
    sb.append(getShortName(logRecord.getSourceClassName()));
    sb.append('.').append(logRecord.getSourceMethodName()).append(": ");
    sb.append(logRecord.getMessage()).append("\n");
    return sb.toString();
}

From source file:com.github.hronom.scrape.dat.rooms.core.grabbers.JxBrowserGrabber.java

private Handler createHandler() {
    return new Handler() {
        @Override//from w w w.  j a v a 2s.  c  o  m
        public void publish(LogRecord record) {
            if (record.getLevel() == Level.INFO) {
                logger.info(record.getMessage());
            } else if (record.getLevel() == Level.WARNING) {
                logger.warn(record.getMessage());
            } else if (record.getLevel() == Level.SEVERE) {
                logger.fatal(record.getMessage());
            } else {
                logger.info(record.getMessage());
            }
        }

        @Override
        public void flush() {

        }

        @Override
        public void close() throws SecurityException {

        }
    };
}

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  w w  w .  j  a v a 2 s. com

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

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

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

    return log;
}

From source file:ch.jamiete.hilda.music.MusicLogFormat.java

@Override
public final 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)] + ']';
    }//w w  w . j ava2 s  .  com

    if (record.getSourceMethodName() != null) {
        log += " (" + record.getSourceMethodName() + ')';
    }

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

    if (record.getThrown() != null) {
        /*log += "\n" + record.getThrown().getMessage();
                
        for (StackTraceElement element : record.getThrown().getStackTrace()) {
        log += "\n" + element.toString();
        }*/
        log += '\n' + ExceptionUtils.getStackTrace(record.getThrown());
    }

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

    return log;
}

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  v  a2s. 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:io.stallion.services.LogFilter.java

@Override
public boolean isLoggable(LogRecord record) {
    Level overrideLevel = packageLogLevelMap.getOrDefault(toPackageName(record), null);
    if (overrideLevel != null) {
        if (record.getLevel().intValue() >= overrideLevel.intValue()) {
            return true;
        } else {/* w  w  w. j  a v a2  s .  com*/
            return false;
        }
    }
    return record.getLevel().intValue() >= defaultLevel.intValue();
}

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  w  w.  ja  va 2 s  .  c o 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:ffx.ui.LogHandler.java

/**
 * {@inheritDoc}/*from  ww w . ja va 2 s.c om*/
 *
 * Publish a LogRecord.
 *
 * @since 1.0.
 */
@Override
public synchronized void publish(LogRecord record) {
    if (record.getLevel() == Level.OFF) {
        if (record.getMessage().toLowerCase().contains("algorithm failure:")) {
            mainPanel.setExitType(MainPanel.ExitStatus.ALGORITHM_FAILURE);
        }
        return;
    }
    /**
     * Check if the record is loggable and that we have not already
     * encountered a fatal error.
     */
    if (!isLoggable(record) || fatal) {
        return;
    }
    String msg;
    try {
        msg = getFormatter().format(record);
    } catch (Exception e) {
        /**
         * We don't want to throw an exception here, but we report the
         * exception to any registered ErrorManager.
         */
        reportError(null, e, ErrorManager.FORMAT_FAILURE);
        return;
    }
    try {
        if (record.getLevel() == Level.SEVERE) {
            fatal = true;
            System.err.println(msg);

            Throwable throwable = record.getThrown();
            if (throwable != null) {
                System.err.println(String.format(" Exception %s logged.", throwable));
            }

            // If tryCatchSevere, and the throwable (if it exists) is not an Error, then...
            if (tryCatchSevere && (throwable == null || !(throwable instanceof Error))) {
                System.err.println(" Force Field X may not continue.");
                System.err.println(" Throwing new error...");
                fatal = false;
                if (throwable != null) {
                    throw new LoggerSevereError(throwable);
                } else {
                    throw new LoggerSevereError(" Unknown exception");
                }
            }

            System.err.println(" Force Field X will not continue.");
            System.err.println(" Shutting down...");
            flush();
            mainPanel.setExitType(MainPanel.ExitStatus.SEVERE);
            mainPanel.exit();
        }
        ModelingShell shell = null;
        if (mainPanel != null) {
            shell = mainPanel.getModelingShell();
        }

        if (!headless && shell != null) {
            shell.appendOutputNl(msg, shell.getResultStyle());
        } else {
            System.out.println(msg);
        }
    } catch (Exception e) {
        /**
         * We don't want to throw an exception here, but we report the
         * exception to any registered ErrorManager.
         */
        reportError(null, e, ErrorManager.WRITE_FAILURE);
    }
}

From source file:ductive.log.JDKToCommonsHandler.java

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

    Log log = logs.get(name);//from   w w w . ja  v a  2s  .  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);
}