Example usage for java.util.logging Level intValue

List of usage examples for java.util.logging Level intValue

Introduction

In this page you can find the example usage for java.util.logging Level intValue.

Prototype

public final int intValue() 

Source Link

Document

Get the integer value for this level.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Level level1 = Level.INFO;
    Level level2 = Level.CONFIG;

    if (level1.intValue() > level2.intValue()) {
        System.out.println("level1 is more severe");
    } else if (level1.intValue() < level2.intValue()) {
        System.out.println("level2 is more severe");
    } else {//from  w w  w .  j a va2  s  .  c  o  m
        System.out.println("level1 == level2");
    }
}

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

/**
 * Logs a message, setting the class, method and source line number using the stack frame index passed in.
 * This is useful if you are wrapping a logging class, and want to include the line number from where
 * the wrapper method is called.//from ww w  .  j ava 2s  . c  o m
 *
 * @param frame - the stack frame to use. Use '2' to log to one level above the caller
 * @param level
 * @param message
 * @param args
 */
public static void logForFrame(int frame, Level level, String message, Object... args) {
    if (getLogLevel().intValue() > level.intValue()) {
        return;
    }
    Throwable t = new Throwable();
    StackTraceElement stackTraceElement = t.getStackTrace()[frame];
    String clz = stackTraceElement.getClassName().replace("io.stallion.", "");
    String method = stackTraceElement.getMethodName() + ":" + t.getStackTrace()[frame].getLineNumber();
    logger.logp(level, clz, method, message, args);
}

From source file:hudson.logging.LogRecorderManager.java

/**
 * Renders the given log recorders as RSS.
 *//*from w  w w.  j ava 2s  .  c o m*/
/*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:com.machinepublishers.jbrowserdriver.LogsServer.java

private static void handleMessage(String message, LinkedList<Entry> entries, Level level, String type,
        Settings settings) {//from  w w  w . j  a v a2  s . co m
    if (settings != null && settings.logsMax() > 0) {
        final Entry entry = new Entry(level, System.currentTimeMillis(), message);
        synchronized (entries) {
            entries.add(entry);
            if (entries.size() > settings.logsMax()) {
                entries.removeFirst();
            }
        }
    }
    if (settings == null || level.intValue() >= settings.loggerLevel()) {
        System.err.println(">" + level.getName() + "/" + type + "/" + message);
    }
}

From source file:com.izforge.izpack.util.LogUtils.java

public static void loadConfiguration(final Properties configuration) throws IOException {
    if (OVERRIDE) {
        LogManager manager = LogManager.getLogManager();

        // Merge global logging properties
        InputStream baseResourceStream = null;
        try {//  www  .j a  v  a2s  . com
            baseResourceStream = LogUtils.class.getResourceAsStream(LOGGING_BASE_CONFIGURATION);
            final Properties baseProps = new Properties();
            baseProps.load(baseResourceStream);
            mergeLoggingConfiguration(configuration, baseProps);
        } finally {
            IOUtils.closeQuietly(baseResourceStream);
        }

        boolean mkdirs = false;
        String pattern = null;
        if (configuration.getProperty("handlers") != null
                && configuration.getProperty("handlers").contains(FILEHANDLER_CLASSNAME)
                && manager.getProperty("handlers").contains(FILEHANDLER_CLASSNAME)) {
            // IzPack maintains just one log file, don't override the existing handler type of it.
            // Special use case: Command line argument -logfile "wins" over the <log-file> tag.
            // Assumption at the moment for optimization: Just FileHandler is used for configurations from install.xml.
            return;
        }
        for (String key : configuration.stringPropertyNames()) {
            if (key.equals(FILEHANDLER_CLASSNAME + ".pattern")) {
                // Workaround for not normalized file paths, for example ${INSTALL_PATH}/../install_log/name.log
                // to get them working before creating ${INSTALL_PATH} in the
                // com.izforge.izpack.installer.unpacker.UnpackerBase.preUnpack phase
                // otherwise the FileHandler will fail when opening files already in constructor and not recover from that.
                pattern = FilenameUtils.normalize(configuration.getProperty(key));
                configuration.setProperty(key, pattern);
            } else if (key.equals(FILEHANDLER_CLASSNAME + ".mkdirs")) {
                // This key goes beyond the capabilities of java.util.logging.FileHandler
                mkdirs = Boolean.parseBoolean(configuration.getProperty(key));
                configuration.remove(key);
            }
        }
        if (mkdirs && pattern != null) {
            FileUtils.forceMkdirParent(new File(pattern));
        }

        // Merge user settings compiled in
        final Properties userProps = new Properties();
        InputStream userPropsStream = LogUtils.class
                .getResourceAsStream(ResourceManager.getInstallLoggingConfigurationResourceName());
        try {
            if (userPropsStream != null) {
                userProps.load(userPropsStream);
                for (String userPropName : userProps.stringPropertyNames()) {
                    if (userPropName.endsWith(".level") && !userPropName.startsWith(FILEHANDLER_CLASSNAME)) {
                        String level = userProps.getProperty(userPropName);
                        if (level != null) {
                            configuration.setProperty(userPropName, level);
                        }
                    }
                }
            }
        } finally {
            IOUtils.closeQuietly(userPropsStream);
        }

        InputStream defaultResourceStream = null;
        try {
            defaultResourceStream = LogUtils.class.getResourceAsStream(LOGGING_CONFIGURATION);
            final Properties defaultProps = new Properties();
            defaultProps.load(defaultResourceStream);
            mergeLoggingConfiguration(configuration, defaultProps);
        } finally {
            IOUtils.closeQuietly(defaultResourceStream);
        }

        if (Debug.isDEBUG()) {
            configuration.setProperty(FILEHANDLER_CLASSNAME + ".level", Level.FINE.toString());
            configuration.setProperty(ConsoleHandler.class.getName() + ".level", Level.FINE.toString());
        }

        // Set general log level which acts as filter in front of all handlers
        String fileLevelName = configuration.getProperty(FILEHANDLER_CLASSNAME + ".level",
                Level.ALL.toString());
        Level fileLevel = Level.ALL;
        if (fileLevelName != null) {
            fileLevel = Level.parse(fileLevelName);
        }

        String consoleLevelName = configuration.getProperty(CONSOLEHANDLER_CLASSNAME + ".level",
                Level.INFO.toString());
        Level consoleLevel = Level.INFO;
        if (consoleLevelName != null) {
            consoleLevel = Level.parse(consoleLevelName);
        }

        configuration.setProperty(".level",
                (fileLevel.intValue() < consoleLevel.intValue()) ? fileLevelName : consoleLevelName);

        final PipedOutputStream out = new PipedOutputStream();
        final PipedInputStream in = new PipedInputStream(out);
        try {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        configuration.store(out, null);
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        IOUtils.closeQuietly(out);
                    }
                }
            }).start();

            manager.readConfiguration(in);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
}

From source file:net.community.chest.gitcloud.facade.ServletUtils.java

public static final Log wrapServletContext(final ServletContext context, final Level thresholdLevel) {
    if ((context == null) || (thresholdLevel == null)) {
        throw new IllegalArgumentException("Incomplete wrapper specification");
    }/*from www .  j  av a  2 s .c om*/

    return new AbstractJULWrapper() {
        @Override
        public void log(Level level, Object message, Throwable t) {
            if (isEnabled(level)) {
                if (t == null) {
                    context.log(level.getName() + ": " + message);
                } else {
                    context.log(level.getName() + ": " + message, t);
                }
            }
        }

        @Override
        public boolean isEnabled(Level level) {
            if (Level.OFF.equals(thresholdLevel)) {
                return false;
            }

            if (Level.ALL.equals(thresholdLevel)) {
                return true;
            }

            if (level.intValue() >= thresholdLevel.intValue()) {
                return true;
            } else {
                return false; // debug breakpoint
            }
        }
    };
}

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   w ww . j  a  va 2 s.c  o m
}

From source file:org.osiam.addons.selfadministration.exception.OsiamExceptionHandler.java

private void setLoggingInformation(Throwable t) {
    Level level = getLogLevel(LOGGER);
    if (level != null && level.intValue() <= Level.INFO.intValue()) {
        modelAndView.addObject("exception", t);
    }/*from  w w  w  .j a  v  a2 s  .  c o  m*/
}

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  w w  w  .  ja v  a2s. 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: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 {//from   w ww . j a v a  2s .  c o  m
            return false;
        }
    }
    return record.getLevel().intValue() >= defaultLevel.intValue();
}