Example usage for java.util.logging Level getName

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

Return the non-localized string name of the Level.

Usage

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  a v a  2s  .co  m*/

    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:com.machinepublishers.jbrowserdriver.LogsServer.java

private static void handleMessage(String message, LinkedList<Entry> entries, Level level, String type,
        Settings settings) {//from  w w w . ja  v  a  2s .  c  o  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:me.st28.flexseries.flexlib.log.LogHelper.java

private static void logFromClass(Level level, Class clazz, String message) {
    Validate.notNull(clazz, "Class cannot be null.");
    Validate.notNull(message, "Message cannot be null.");

    if (FlexPlugin.class.isAssignableFrom(clazz)) {
        JavaPlugin plugin = JavaPlugin.getPlugin(clazz);

        if (plugin == null) {
            throw new IllegalArgumentException("Plugin '" + clazz.getCanonicalName() + "' not found.");
        }//from   ww  w  . ja va2 s.  c  o  m

        if (!(plugin instanceof FlexPlugin)) {
            throw new IllegalArgumentException("Plugin '" + plugin.getName() + "' is not a FlexPlugin.");
        }

        FlexPlugin fp = (FlexPlugin) plugin;

        if (level == Level.INFO) {
            info(fp, message);
        } else if (level == Level.WARNING) {
            warning(fp, message);
        } else if (level == Level.SEVERE) {
            severe(fp, message);
        } else if (level == null) {
            debug(fp, message);
        }
        throw new IllegalArgumentException("Invalid log level '" + level.getName() + "'");
    }

    if (FlexModule.class.isAssignableFrom(clazz)) {
        throw new IllegalArgumentException("Invalid log level '" + level.getName() + "'");
    }

    throw new IllegalArgumentException(
            "Class '" + clazz.getCanonicalName() + "' must be an instance of FlexPlugin or FlexModule.");
}

From source file:edu.usu.sdl.openstorefront.web.action.admin.LoggingAction.java

@DefaultHandler
public Resolution viewLoggers() {
    StringBuilder results = new StringBuilder();

    List<String> allLoggers = LogManager.getLoggingMXBean().getLoggerNames();
    Collections.sort(allLoggers);
    results.append(//from  w w w. ja  va  2 s  .  c  o m
            "<table border='1'><tr style='background-color: lightgrey; '><th >Logger</th><th>Level</th><th>Handlers</th>");
    for (String name : allLoggers) {
        results.append("<tr>");
        Level levelLocal = LogManager.getLogManager().getLogger(name).getLevel();
        String levelName = "";
        if (levelLocal != null) {
            levelName = levelLocal.getName();
        }
        results.append("<td><b>").append(name).append("</b></td><td> ").append(levelName).append("</td>");

        results.append("<td>");
        Logger localLogger = LogManager.getLogManager().getLogger(name);
        for (Handler handlerLocal : localLogger.getHandlers()) {
            results.append(handlerLocal.getClass().getName()).append(" = ")
                    .append(handlerLocal.getLevel().getName()).append("<br>");
        }
        results.append("</td>");

        results.append("</tr>");
    }
    results.append("</table>");
    return new StreamingResolution("text/html", results.toString());
}

From source file:de.static_interface.sinklibrary.util.Debug.java

public static void logToFile(@Nonnull Level level, @Nonnull String message) {
    boolean enabled;
    try {/*from www  . j  a va 2s .  com*/
        enabled = SinkLibrary.getInstance().getSettings().isLogEnabled();
    } catch (Exception ignored) {
        return;
    }
    if (!enabled) {
        return;
    }

    File logFile = new File(SinkLibrary.getInstance().getCustomDataFolder(), "Debug.log");
    if (!failed && !logFile.exists()) // Prevent creating/checking every time
    {
        if (!FileUtil.createFile(logFile)) {
            return;
        }
        failed = true;
        return;
    } else if (failed) {
        return;
    }
    if (fileWriter == null) {
        try {
            fileWriter = new FileWriter(logFile, true);
        } catch (IOException e) {
            Bukkit.getLogger().log(Level.SEVERE, "Couldn't create FileWriter: ", e);
            return;
        }
    }

    String newLine = System.getProperty("line.separator");
    SimpleDateFormat format = new SimpleDateFormat("dd.MM.YYYY-hh:mm:ss");
    String date = format.format(new Date());

    try {
        fileWriter.write('[' + date + ' ' + level.getName() + "]: " + message + newLine);
    } catch (IOException ignored) {
        //Do nothing...
    }
}

From source file:org.jboss.capedwarf.common.env.AbstractEnvironment.java

public void log(String category, Level level, String msg, Throwable t) {
    if (level == null) {
        verbose(category, msg, t);//from  w  w w. j a  v  a 2s .  co  m
        return;
    }

    String name = level.getName();
    if (Level.SEVERE.equals(level))
        name = "ERROR";
    else if (Level.CONFIG.equals(level))
        name = "DEBUG";

    List<Class<?>> types = new ArrayList<Class<?>>();
    types.add(String.class);
    types.add(String.class);
    if (t != null)
        types.add(Throwable.class);

    try {
        Method m = getMethod(name, types.toArray(new Class<?>[types.size()]));

        List<Object> args = new ArrayList<Object>();
        args.add(category);
        args.add(msg);
        if (t != null)
            args.add(t);

        m.invoke(null, args.toArray(new Object[args.size()]));
    } catch (Exception ignored) {
        verbose(category, msg, t);
    }
}

From source file:contestTabulation.Main.java

private static void persistData(Level level, Collection<School> schools,
        Map<Test, List<Student>> categoryWinners, Map<Subject, List<School>> categorySweepstakesWinners,
        List<School> sweepstakesWinners) throws JSONException {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {/*www  .j a v a2  s  . c om*/
        tx.begin();
        pm.makePersistentAll(schools);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }

    List<Entity> categoryWinnersEntities = new ArrayList<Entity>();
    for (Entry<Test, List<Student>> categoryWinnerEntry : categoryWinners.entrySet()) {
        String entityKey = categoryWinnerEntry.getKey().toString() + "_" + level.toString();
        Entity categoryWinnersEntity = new Entity("CategoryWinners", entityKey,
                KeyFactory.createKey("Level", level.getName()));

        List<Key> studentKeys = new ArrayList<Key>();
        for (Student student : categoryWinnerEntry.getValue()) {
            studentKeys.add(student.getKey());
        }
        categoryWinnersEntity.setProperty("students", studentKeys);

        categoryWinnersEntities.add(categoryWinnersEntity);
    }
    datastore.put(categoryWinnersEntities);

    List<Entity> categorySweepstakesWinnersEntities = new ArrayList<Entity>();
    for (Entry<Subject, List<School>> categorySweepstakesWinnerEntry : categorySweepstakesWinners.entrySet()) {
        String entityKey = categorySweepstakesWinnerEntry.getKey().toString() + "_" + level.toString();
        Entity categoryWinnersEntity = new Entity("CategorySweepstakesWinners", entityKey,
                KeyFactory.createKey("Level", level.getName()));

        List<Key> schoolKeys = new ArrayList<Key>();
        for (School school : categorySweepstakesWinnerEntry.getValue()) {
            schoolKeys.add(school.getKey());
        }
        categoryWinnersEntity.setProperty("schools", schoolKeys);

        categorySweepstakesWinnersEntities.add(categoryWinnersEntity);
    }
    datastore.put(categorySweepstakesWinnersEntities);

    List<Entity> visualizationEntities = new ArrayList<Entity>();

    Entity sweepstakesWinnerEntity = new Entity("SweepstakesWinners", level.toString(),
            KeyFactory.createKey("Level", level.getName()));
    List<Key> schoolKeys = new ArrayList<Key>();
    for (School school : sweepstakesWinners) {
        schoolKeys.add(school.getKey());
    }
    sweepstakesWinnerEntity.setProperty("schools", schoolKeys);
    datastore.put(sweepstakesWinnerEntity);

    HashMap<Test, List<Integer>> scores = new HashMap<Test, List<Integer>>();
    Test[] tests = Test.getTests(level);
    for (Test test : tests) {
        scores.put(test, new ArrayList<Integer>());
    }

    for (School school : schools) {
        for (Student student : school.getStudents()) {
            for (Entry<Subject, Score> scoreEntry : student.getScores().entrySet()) {
                if (scoreEntry.getValue().isNumeric()) {
                    scores.get(Test.fromSubjectAndGrade(student.getGrade(), scoreEntry.getKey()))
                            .add(scoreEntry.getValue().getScoreNum());
                }
            }
        }
    }

    for (Test test : tests) {
        Entity visualizationsEntity = new Entity("Visualization", test.toString(),
                KeyFactory.createKey("Level", level.getName()));
        visualizationsEntity.setProperty("scores", scores.get(test));
        visualizationEntities.add(visualizationsEntity);
    }
    datastore.put(visualizationEntities);
}

From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java

@GET
@RequireAdmin/*from  w ww  .  j a  v  a2s . co m*/
@APIDescription("Gets Loggers in the system")
@Produces({ MediaType.APPLICATION_JSON })
@DataType(LoggerView.class)
@Path("/loggers")
public List<LoggerView> getLoggers() {
    List<LoggerView> loggers = new ArrayList<>();

    List<String> allLoggers = LogManager.getLoggingMXBean().getLoggerNames();
    Collections.sort(allLoggers);

    for (String name : allLoggers) {
        LoggerView loggerView = new LoggerView();
        loggerView.setName(name);

        Level levelLocal = LogManager.getLogManager().getLogger(name).getLevel();
        String levelName = "";
        if (levelLocal != null) {
            levelName = levelLocal.getName();
        }
        loggerView.setLevel(levelName);

        Logger localLogger = LogManager.getLogManager().getLogger(name);
        for (Handler handlerLocal : localLogger.getHandlers()) {
            loggerView.getHandlers()
                    .add(handlerLocal.getClass().getName() + " = " + handlerLocal.getLevel().getName());
        }
        loggers.add(loggerView);
    }

    return loggers;
}

From source file:com.tealcube.minecraft.bukkit.facecore.logging.PluginLogger.java

/**
 * Logs a message with a given {@link java.util.logging.Level}.
 *
 * @param level   Level of logging message
 * @param message message to log//  w  ww. j  a va 2  s. c o  m
 */
public void log(Level level, String message) {
    Validate.notNull(level, "level cannot be null");
    Validate.notNull(message, "message cannot be null");
    Validate.notNull(file, "file cannot be null");
    File writeFile = file;
    if (!IOUtils.createFile(writeFile)) {
        return;
    }
    try (FileWriter fileWriter = new FileWriter(writeFile, true);
            PrintWriter writer = new PrintWriter(fileWriter)) {
        writer.println(
                "[" + level.getName() + "] " + Calendar.getInstance().getTime().toString() + " | " + message);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.tealcube.minecraft.bukkit.facecore.logging.PluginLogger.java

/**
 * Logs messages with a given {@link java.util.logging.Level}.
 *
 * @param level    Level of logging message
 * @param messages messages to log/*from   w  ww.  j  av  a  2s. com*/
 */
public void log(Level level, Iterable<String> messages) {
    Validate.notNull(level, "level cannot be null");
    Validate.notNull(messages, "message cannot be null");
    Validate.notNull(file, "file cannot be null");
    File writeFile = file;
    if (!IOUtils.createFile(writeFile)) {
        return;
    }
    try (FileWriter fileWriter = new FileWriter(writeFile, true);
            PrintWriter writer = new PrintWriter(fileWriter)) {
        String time = Calendar.getInstance().getTime().toString();
        for (String message : messages) {
            writer.println("[" + level.getName() + "] " + time + " | " + message);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}