Search in sources :

Example 1 with Level

use of sun.util.logging.PlatformLogger.Level in project jdk8u_jdk by JetBrains.

the class PlatformLoggerTest method checkLoggerLevel.

private static void checkLoggerLevel(PlatformLogger logger, Level level) {
    PlatformLogger.Level plevel = PlatformLogger.Level.valueOf(level.getName());
    if (plevel != logger.level()) {
        throw new RuntimeException("Retrieved PlatformLogger level " + logger.level() + " is not the same as set level " + plevel);
    }
    // check the level set in java.util.logging.Logger
    Logger javaLogger = LogManager.getLogManager().getLogger(logger.getName());
    Level javaLevel = javaLogger.getLevel();
    if (javaLogger.getLevel() != level) {
        throw new RuntimeException("Retrieved backing java.util.logging.Logger level " + javaLevel + " is not the expected " + level);
    }
}
Also used : Level(sun.util.logging.PlatformLogger.Level) Level(sun.util.logging.PlatformLogger.Level) PlatformLogger(sun.util.logging.PlatformLogger) PlatformLogger(sun.util.logging.PlatformLogger)

Example 2 with Level

use of sun.util.logging.PlatformLogger.Level in project jdk8u_jdk by JetBrains.

the class PlatformLoggerTest method checkJavaLoggerLevel.

private static void checkJavaLoggerLevel(Logger logger, Level level) {
    // This method exercise the mapping of java level to platform level
    // when the java level is not one of the standard levels...
    System.out.println("Testing Java Level with: " + level.getName());
    // create a brand new java logger
    Logger javaLogger = (Logger) LoggingSupport.getLogger(logger.getName() + "." + level.getName());
    // Set a non standard java.util.logging.Level on the java logger
    // (except for OFF & ALL - which will remain unchanged)
    int intValue = level.intValue();
    if (level != Level.ALL && level != Level.OFF) {
        intValue -= 7;
    }
    javaLogger.setLevel(Level.parse(String.valueOf(intValue)));
    // check the level set in java.util.logging.Logger
    Level effectiveLevel = javaLogger.getLevel();
    System.out.println("Effective Java Level used is: " + effectiveLevel);
    if (effectiveLevel.intValue() != intValue) {
        throw new RuntimeException("Retrieved backing java.util.logging.Logger level.intValue() " + effectiveLevel.intValue() + " is not the expected " + intValue);
    }
    if (intValue != level.intValue() && javaLogger.getLevel() == level) {
        throw new RuntimeException("Retrieved backing java.util.logging.Logger level " + effectiveLevel + " is " + level);
    }
    if (intValue == level.intValue() && javaLogger.getLevel() != level) {
        throw new RuntimeException("Retrieved backing java.util.logging.Logger level " + effectiveLevel + " is not " + level);
    }
    // check the level set in the PlatformLogger
    PlatformLogger plogger = PlatformLogger.getLogger(javaLogger.getName());
    PlatformLogger.Level expected = PlatformLogger.Level.valueOf(level.getName());
    if (plogger.level() != expected) {
        throw new RuntimeException("Retrieved backing PlatformLogger level " + plogger.level() + " is not the expected " + expected);
    }
}
Also used : Level(sun.util.logging.PlatformLogger.Level) Level(sun.util.logging.PlatformLogger.Level) PlatformLogger(sun.util.logging.PlatformLogger) PlatformLogger(sun.util.logging.PlatformLogger)

Example 3 with Level

use of sun.util.logging.PlatformLogger.Level in project jdk8u_jdk by JetBrains.

the class PlatformLoggerTest method checkPlatformLoggerLevels.

private static void checkPlatformLoggerLevels(PlatformLogger... loggers) {
    final Level[] levels = new Level[] { Level.ALL, Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.INFO, Level.OFF, Level.SEVERE, Level.WARNING };
    int count = PlatformLogger.Level.values().length;
    if (levels.length != count) {
        throw new RuntimeException("There are " + count + " PlatformLogger.Level members, but " + levels.length + " standard java.util.logging levels - the numbers should be equal.");
    }
    // check mappings
    for (Level level : levels) {
        checkPlatformLoggerLevelMapping(level);
    }
    for (Level level : levels) {
        PlatformLogger.Level platformLevel = PlatformLogger.Level.valueOf(level.getName());
        for (PlatformLogger logger : loggers) {
            // setLevel(PlatformLogger.Level)
            logger.setLevel(platformLevel);
            checkLoggerLevel(logger, level);
            // setLevel(int)
            logger.setLevel(ALL);
            checkLoggerLevel(logger, Level.ALL);
        }
    }
    Logger javaLogger = Logger.getLogger("foo.bar.baz");
    for (Level level : levels) {
        checkJavaLoggerLevel(javaLogger, level);
    }
}
Also used : Level(sun.util.logging.PlatformLogger.Level) Level(sun.util.logging.PlatformLogger.Level) PlatformLogger(sun.util.logging.PlatformLogger) PlatformLogger(sun.util.logging.PlatformLogger)

Aggregations

PlatformLogger (sun.util.logging.PlatformLogger)3 Level (sun.util.logging.PlatformLogger.Level)3