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:MainClass.java

public static void main(String[] args) {
    logger.setUseParentHandlers(false);//w w w .ja  v  a  2  s.  c om
    Handler conHdlr = new ConsoleHandler();
    conHdlr.setFormatter(new Formatter() {
        public String format(LogRecord record) {
            return record.getLevel() + "  :  " + record.getSourceClassName() + " -:- "
                    + record.getSourceMethodName() + " -:- " + record.getMessage() + "\n";
        }
    });
    logger.addHandler(conHdlr);
    logMessages();
}

From source file:Main.java

public static void main(String[] args) {
    logger.addHandler(new Handler() {
        public void publish(LogRecord logRecord) {
            strHolder.add(logRecord.getLevel() + ":");
            strHolder.add(logRecord.getSourceClassName() + ":");
            strHolder.add(logRecord.getSourceMethodName() + ":");
            strHolder.add("<" + logRecord.getMessage() + ">");
            strHolder.add("\n");
        }/*  w w w.  jav a2  s .com*/

        public void flush() {
        }

        public void close() {
        }
    });
    logger.warning("Logging Warning");
    logger.info("Logging Info");
    System.out.print(strHolder);
}

From source file:hudson.logging.LogRecorderManager.java

/**
 * Renders the given log recorders as RSS.
 *//*from   www  . j  av a2s .com*/
/*package*/ static void doRss(StaplerRequest req, StaplerResponse rsp, List<LogRecord> logs)
        throws IOException, ServletException {
    // filter log records based on the log level
    String level = req.getParameter("level");
    if (level != null) {
        Level threshold = Level.parse(level);
        List<LogRecord> filtered = new ArrayList<LogRecord>();
        for (LogRecord r : logs) {
            if (r.getLevel().intValue() >= threshold.intValue())
                filtered.add(r);
        }
        logs = filtered;
    }

    RSS.forwardToRss("Hudson log", "", logs, new FeedAdapter<LogRecord>() {
        public String getEntryTitle(LogRecord entry) {
            return entry.getMessage();
        }

        public String getEntryUrl(LogRecord entry) {
            return "log"; // TODO: one URL for one log entry?
        }

        public String getEntryID(LogRecord entry) {
            return String.valueOf(entry.getSequenceNumber());
        }

        public String getEntryDescription(LogRecord entry) {
            return Functions.printLogRecord(entry);
        }

        public Calendar getEntryTimestamp(LogRecord entry) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(entry.getMillis());
            return cal;
        }

        public String getEntryAuthor(LogRecord entry) {
            return Mailer.descriptor().getAdminAddress();
        }
    }, req, rsp);
}

From source file:org.freaknet.gtrends.client.GoogleTrendsClientFactory.java

private static void setLogLevel(CmdLineParser cmdLine) throws SecurityException, IllegalArgumentException {
    final Level level;
    if (cmdLine.getLogLevel() != null) {
        level = Level.parse(cmdLine.getLogLevel());
    } else {/*from  ww w  .  j a  v a2 s.  c o m*/
        level = Level.parse(DEFAULT_LOGGING_LEVEL);
    }
    Logger log = LogManager.getLogManager().getLogger("");

    for (Handler h : log.getHandlers()) {
        log.removeHandler(h);
    }
    Handler handler = new ConsoleHandler();
    handler.setFormatter(new LogFormatter());
    handler.setLevel(level);
    log.setUseParentHandlers(false);

    Logger defaultLog = Logger.getLogger(GoogleConfigurator.getLoggerPrefix());
    defaultLog.addHandler(handler);
    defaultLog.setLevel(level);
    defaultLog.setFilter(new Filter() {
        @Override
        public boolean isLoggable(LogRecord record) {
            if (record.getSourceClassName().startsWith(GoogleConfigurator.getLoggerPrefix())) {
                return (record.getLevel().intValue() >= level.intValue());
            }
            return false;
        }
    });
}

From source file:com.frostvoid.trekwar.server.TrekwarServer.java

/**
 * Initiates logging//from  ww  w  .  j  a  va 2  s. com
 *
 * @throws IOException
 */
private static void initLogging() throws IOException {
    FileHandler fh = new FileHandler(galaxyFileName + ".log");
    fh.setLevel(LOG.getLevel());
    Formatter logFormat = new Formatter() {

        @Override
        public String format(LogRecord rec) {
            StringBuilder buf = new StringBuilder(200);
            buf.append("#");
            buf.append(new java.util.Date());
            buf.append(' ');
            buf.append(rec.getLevel());
            buf.append(' ');
            buf.append(rec.getSourceClassName()).append(".").append(rec.getSourceMethodName());
            buf.append(":\n");
            buf.append(formatMessage(rec));
            buf.append('\n');
            return buf.toString();
        }
    };
    fh.setFormatter(logFormat);

    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(LOG.getLevel());
    Formatter conlogFormat = new Formatter() {
        @Override
        public String format(LogRecord rec) {
            StringBuilder buf = new StringBuilder(200);
            buf.append(rec.getLevel());
            buf.append(": ");
            buf.append(formatMessage(rec));
            buf.append('\n');
            return buf.toString();
        }
    };
    ch.setFormatter(conlogFormat);

    LOG.addHandler(fh);
    LOG.addHandler(ch);
}

From source file:brut.apktool.Main.java

private static void setupLogging(Verbosity verbosity) {
    Logger logger = Logger.getLogger("");
    for (Handler handler : logger.getHandlers()) {
        logger.removeHandler(handler);// w w w  .  j av  a  2s  . c  o m
    }
    LogManager.getLogManager().reset();

    if (verbosity == Verbosity.QUIET) {
        return;
    }

    Handler handler = new Handler() {
        @Override
        public void publish(LogRecord record) {
            if (getFormatter() == null) {
                setFormatter(new SimpleFormatter());
            }

            try {
                String message = getFormatter().format(record);
                if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
                    System.err.write(message.getBytes());
                } else {
                    System.out.write(message.getBytes());
                }
            } catch (Exception exception) {
                reportError(null, exception, ErrorManager.FORMAT_FAILURE);
            }
        }

        @Override
        public void close() throws SecurityException {
        }

        @Override
        public void flush() {
        }
    };

    logger.addHandler(handler);

    if (verbosity == Verbosity.VERBOSE) {
        handler.setLevel(Level.ALL);
        logger.setLevel(Level.ALL);
    } else {
        handler.setFormatter(new Formatter() {
            @Override
            public String format(LogRecord record) {
                return record.getLevel().toString().charAt(0) + ": " + record.getMessage()
                        + System.getProperty("line.separator");
            }
        });
    }
}

From source file:MyHtmlFormatter.java

public String format(LogRecord rec) {
    StringBuffer buf = new StringBuffer(1000);
    if (rec.getLevel().intValue() >= Level.WARNING.intValue()) {
        buf.append("<b>");
        buf.append(rec.getLevel());/*from  www.  ja va2 s  .  c o  m*/
        buf.append("</b>");
    } else {
        buf.append(rec.getLevel());
    }
    buf.append(' ');
    buf.append(rec.getMillis());
    buf.append(' ');
    buf.append(formatMessage(rec));
    buf.append('\n');
    return buf.toString();
}

From source file:ca.phon.app.log.LogHandler.java

@Override
public void publish(LogRecord record) {
    Level logLevel = record.getLevel();
    if (logLevel.intValue() >= getLevel().intValue())
        logBuffer.add(record);/*from  ww  w.j a v a  2 s  . c om*/
}

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  w w w  .  j ava 2s.  co m

    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:at.bitfire.davdroid.log.LogcatHandler.java

@Override
public void publish(LogRecord r) {
    String text = getFormatter().format(r);
    int level = r.getLevel().intValue();

    int end = text.length();
    for (int pos = 0; pos < end; pos += MAX_LINE_LENGTH) {
        String line = text.substring(pos, NumberUtils.min(pos + MAX_LINE_LENGTH, end));

        if (level >= Level.SEVERE.intValue())
            Log.e(r.getLoggerName(), line);
        else if (level >= Level.WARNING.intValue())
            Log.w(r.getLoggerName(), line);
        else if (level >= Level.CONFIG.intValue())
            Log.i(r.getLoggerName(), line);
        else if (level >= Level.FINER.intValue())
            Log.d(r.getLoggerName(), line);
        else/*from   w  w  w .java2  s  .c  o m*/
            Log.v(r.getLoggerName(), line);
    }
}