Example usage for java.util.logging Level toString

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

Introduction

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

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this Level.

Usage

From source file:alluxio.util.LogUtils.java

private static void process(java.util.logging.Logger log, String level, LogInfo result) throws IOException {
    if (log == null) {
        result.setMessage("log is null.");
        return;//from  www .ja  va  2 s .c  om
    }
    if (level != null) {
        log.setLevel(java.util.logging.Level.parse(level));
        result.setMessage("Setting Level to " + level);
    }

    java.util.logging.Level lev;
    while ((lev = log.getLevel()) == null) {
        log = log.getParent();
    }
    result.setLevel(lev.toString());
}

From source file:contestTabulation.Main.java

private static Map<String, String> getSchoolGroups(Level level, Entity contestInfo) {
    String schoolGroupsNamesString = ((Text) contestInfo.getProperty(level.toString() + "SchoolGroupsNames"))
            .getValue();// w w  w .j av  a  2s . c  om
    if (schoolGroupsNamesString != null) {
        return (Map<String, String>) new Yaml().load(schoolGroupsNamesString);
    } else {
        return new HashMap<String, String>();
    }
}

From source file:org.eclipse.ecr.common.logging.JavaUtilLoggingHelper.java

/**
 * Redirects {@code java.util.logging} to Apache Commons Logging do not log
 * below the threshold level./*w  ww.  java2  s. c o m*/
 *
 * @since 5.4.2
 */
public static synchronized void redirectToApacheCommons(Level threshold) {
    if (activeHandler != null) {
        return;
    }
    try {
        Logger rootLogger = LogManager.getLogManager().getLogger("");
        for (Handler handler : rootLogger.getHandlers()) {
            rootLogger.removeHandler(handler);
        }
        activeHandler = new LogHandler();
        activeHandler.setLevel(threshold);
        rootLogger.addHandler(activeHandler);
        rootLogger.setLevel(threshold);
        log.info("Redirecting java.util.logging to Apache Commons Logging, threshold is "
                + threshold.toString());
    } catch (Exception e) {
        log.error("Handler setup failed", e);
    }
}

From source file:org.nuxeo.common.logging.JavaUtilLoggingHelper.java

/**
 * Redirects {@code java.util.logging} to Apache Commons Logging do not log
 * below the threshold level.//from   w w  w.  j a  v a 2  s . co m
 *
 * @since 5.4.2
 */
public static synchronized void redirectToApacheCommons(Level threshold) {
    if (activeHandler != null) {
        return;
    }
    try {
        Logger rootLogger = LogManager.getLogManager().getLogger("");
        for (Handler handler : rootLogger.getHandlers()) {
            rootLogger.removeHandler(handler);
        }
        activeHandler = new LogHandler();
        activeHandler.setLevel(threshold);
        rootLogger.addHandler(activeHandler);
        rootLogger.setLevel(threshold);
        log.info("Redirecting java.util.logging to Apache Commons Logging, threshold is "
                + threshold.toString());
    } catch (SecurityException e) {
        log.error("Handler setup failed", e);
    }
}

From source file:contestTabulation.Main.java

private static void updateRegistrations(Level level, Map<String, School> schools) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    for (School school : schools.values()) {
        Filter schoolNameFilter = new FilterPredicate("schoolName", FilterOperator.EQUAL, school.getName());
        Filter schoolLevelFilter = new FilterPredicate("schoolLevel", FilterOperator.EQUAL, level.toString());
        Filter regTypeFilter = new FilterPredicate("registrationType", FilterOperator.EQUAL, "coach");

        Query query = new Query("registration")
                .setFilter(CompositeFilterOperator.and(schoolNameFilter, schoolLevelFilter, regTypeFilter));
        List<Entity> registrations = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());

        if (registrations.size() > 0) {
            Entity registration = registrations.get(0);
            for (Entry<Test, Integer> numTest : school.getNumTests().entrySet()) {
                registration.setProperty(numTest.getKey().toString(), numTest.getValue());
            }/*from w  ww .j a v a 2 s . c o m*/
            datastore.put(registration);
        }
    }
}

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 {//from w w w  . j a va  2s.c  o  m
        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:com.gisgraphy.domain.geoloc.service.fulltextsearch.SolrClient.java

public void setSolRLogLevel(Level level) {
    Assert.notNull(level, "you can not specify a null level");
    Assert.notNull(multiThreadedHttpConnectionManager,
            "httpconnectionManager should not be null, can not set log level");
    Assert.notNull(URL, "Solr URL should not be null, can not set log level");
    HttpClient client = new HttpClient(multiThreadedHttpConnectionManager);
    PostMethod method = new PostMethod(this.URL + "admin/logging");
    method.setParameter("root", level.toString().toUpperCase());
    method.setParameter("submit", "set");
    try {//from w w  w .j  av  a2s. c o m
        try {
            int responseCode = client.executeMethod(method);
            logger.info("Set solr log Level to " + level);
            String responseBody = method.getResponseBodyAsString();
            if (responseCode >= 500) {
                throw new RuntimeException("Can not set solr log level to " + level
                        + " because response code is not OK (" + responseCode + "): " + responseBody);
            }
        } catch (Exception e) {
            throw new RuntimeException("Can not set solr log level to " + level, e);
        }
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cyberway.issue.io.ArchiveReader.java

/**
 * Log on stderr.//  w  w w .  j  a  v  a2  s  .  co  m
 * Logging should go via the logging system.  This method
 * bypasses the logging system going direct to stderr.
 * Should not generally be used.  Its used for rare messages
 * that come of cmdline usage of ARCReader ERRORs and WARNINGs.
 * Override if using ARCReader in a context where no stderr or
 * where you'd like to redirect stderr to other than System.err.
 * @param level Level to log message at.
 * @param message Message to log.
 */
public void logStdErr(Level level, String message) {
    System.err.println(level.toString() + " " + message);
}

From source file:gemlite.core.internal.db.AsyncEventHelper.java

/**
 * Log the given message and exception to the provided logger.
 * //from   w w w .  j ava2 s  .c  o m
 * @param logger
 *          the {@link Logger} to log the message to
 * @param level
 *          the {@link Level} to use for logging the message
 * @param t
 *          the exception whose backtrace is to be logged; can be null in
 *          which case it is ignored
 * @param message
 *          the message to be logged
 */
public final void log(Logger logger, Level level, Throwable t, final String message) {
    StringBuilder sb = new StringBuilder();
    sb.append(message).append(": ");
    if (t != null) {
        getStackTrace(t, sb);
    }
    if (Level.SEVERE.equals(level.toString()))
        logger.error(sb.toString());
    else
        logger.info(sb.toString());
}

From source file:gov.llnl.lc.smt.command.config.SmtConfig.java

/**
 * Describe the method here//from w  w  w .  ja va2  s .  co m
 *
 * @see     describe related java objects
 *
 * @param options
 ***********************************************************/
private boolean configLogging() {
    boolean status = false;
    // fix any changes to the logging system
    if (sConfigMap.containsKey(SmtProperty.SMT_LOG_FILE.getName())) {
        status = true; // a valid argument
        String pattern = sConfigMap.get(SmtProperty.SMT_LOG_FILE.getName());

        java.util.logging.Handler hpcHandlerF = null;
        try {
            // set the file pattern
            hpcHandlerF = new java.util.logging.FileHandler(pattern, true);
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block, probably because path to logging is not set up
            // a typical error is;
            // java.io.IOException: Couldn't get lock for %h/.smt/smt-console%u.log
            e.printStackTrace();
        }
        logger.addHandler(hpcHandlerF);
        Handler[] lhand = logger.getHandlers();

        if (lhand.length > 1) {
            // changing to a new handler, get rid of the original one
            lhand[0].close();
            logger.removeHandler(lhand[0]);
            logger.info("Replaced the original log handler");
        }
        // Done, may want to clean up previous log file,if any??

    }

    if (sConfigMap.containsKey(SmtProperty.SMT_LOG_LEVEL.getName())) {
        status = true; // a valid argument
        Level level = logger.getLevel(); // just keep the default
        try {
            Level l = Level.parse(sConfigMap.get(SmtProperty.SMT_LOG_LEVEL.getName()));
            level = l;
        } catch (IllegalArgumentException iae) {

        }
        logger.info("Setting the log level to: " + level.toString());
        logger.setLevel(level);
    }
    return status;
}