Java Code Examples for sun.util.logging.PlatformLogger#getLogger()

The following examples show how to use sun.util.logging.PlatformLogger#getLogger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HijrahChronology.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For each Hijrah variant listed, create the HijrahChronology and register it.
 * Exceptions during initialization are logged but otherwise ignored.
 */
private static void registerVariants() {
    for (String name : calendarProperties.stringPropertyNames()) {
        if (name.startsWith(PROP_PREFIX)) {
            String id = name.substring(PROP_PREFIX.length());
            if (id.indexOf('.') >= 0) {
                continue;   // no name or not a simple name of a calendar
            }
            if (id.equals(INSTANCE.getId())) {
                continue;           // do not duplicate the default
            }
            try {
                // Create and register the variant
                HijrahChronology chrono = new HijrahChronology(id);
                AbstractChronology.registerChrono(chrono);
            } catch (DateTimeException ex) {
                // Log error and continue
                PlatformLogger logger = PlatformLogger.getLogger("java.time.chrono");
                logger.severe("Unable to initialize Hijrah calendar: " + id, ex);
            }
        }
    }
}
 
Example 2
Source File: SourceClassName.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void writeLogRecords(PrintStream logps) throws Exception {
    PrintStream err = System.err;
    try {
        System.setErr(logps);

        Object[] params = new Object[] { new Long(1), "string"};
        PlatformLogger plog = PlatformLogger.getLogger("test.log.foo");
        plog.severe("Log message {0} {1}", (Object[]) params);

        // create a java.util.logging.Logger
        // now java.util.logging.Logger should be created for each platform logger
        Logger logger = Logger.getLogger("test.log.bar");
        logger.log(Level.SEVERE, "Log message {0} {1}", params);

        plog.severe("Log message {0} {1}", (Object[]) params);
    } finally {
        logps.flush();
        logps.close();
        System.setErr(err);
    }
}
 
Example 3
Source File: HijrahChronology.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For each Hijrah variant listed, create the HijrahChronology and register it.
 * Exceptions during initialization are logged but otherwise ignored.
 */
private static void registerVariants() {
    for (String name : calendarProperties.stringPropertyNames()) {
        if (name.startsWith(PROP_PREFIX)) {
            String id = name.substring(PROP_PREFIX.length());
            if (id.indexOf('.') >= 0) {
                continue;   // no name or not a simple name of a calendar
            }
            if (id.equals(INSTANCE.getId())) {
                continue;           // do not duplicate the default
            }
            try {
                // Create and register the variant
                HijrahChronology chrono = new HijrahChronology(id);
                AbstractChronology.registerChrono(chrono);
            } catch (DateTimeException ex) {
                // Log error and continue
                PlatformLogger logger = PlatformLogger.getLogger("java.time.chrono");
                logger.severe("Unable to initialize Hijrah calendar: " + id, ex);
            }
        }
    }
}
 
Example 4
Source File: FontConfiguration.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void loadProperties(InputStream in) throws IOException {
    //loadingProperties = true;
    //StringID starts from "1", "0" is reserved for "not defined"
    stringIDNum = 1;
    stringIDs = new short[1000];
    stringTable = new StringBuilder(4096);

    if (verbose && logger == null) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    new PropertiesHandler().load(in);

    //loadingProperties = false;
    stringIDs = null;
    stringTable = null;
}
 
Example 5
Source File: FontConfiguration.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public FontConfiguration(SunFontManager fm) {
    if (FontUtilities.debugFonts()) {
        FontUtilities.getLogger()
            .info("Creating standard Font Configuration");
    }
    if (FontUtilities.debugFonts() && logger == null) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    fontManager = fm;
    setOsNameAndVersion();  /* static initialization */
    setEncoding();          /* static initialization */
    /* Separating out the file location from the rest of the
     * initialisation, so the caller has the option of doing
     * something else if a suitable file isn't found.
     */
    findFontConfigFile();
}
 
Example 6
Source File: HijrahChronology.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For each Hijrah variant listed, create the HijrahChronology and register it.
 * Exceptions during initialization are logged but otherwise ignored.
 */
private static void registerVariants() {
    for (String name : calendarProperties.stringPropertyNames()) {
        if (name.startsWith(PROP_PREFIX)) {
            String id = name.substring(PROP_PREFIX.length());
            if (id.indexOf('.') >= 0) {
                continue;   // no name or not a simple name of a calendar
            }
            if (id.equals(INSTANCE.getId())) {
                continue;           // do not duplicate the default
            }
            try {
                // Create and register the variant
                HijrahChronology chrono = new HijrahChronology(id);
                AbstractChronology.registerChrono(chrono);
            } catch (DateTimeException ex) {
                // Log error and continue
                PlatformLogger logger = PlatformLogger.getLogger("java.time.chrono");
                logger.severe("Unable to initialize Hijrah calendar: " + id, ex);
            }
        }
    }
}
 
Example 7
Source File: CustomLogManagerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    String mgr = System.getProperty("java.util.logging.manager");
    if (!mgr.equals("CustomLogManager")) {
        throw new RuntimeException("java.util.logging.manager not set");
    }

    Logger.getLogger(CustomLogManagerTest.class.getName());
    Logger.getLogger("org.foo.Foo");
    Logger.getLogger("org.foo.bar.Foo", RESOURCE_BUNDLE);
    // platform logger will be set with the default system resource bundle
    PlatformLogger.getLogger("org.openjdk.core.logger");

    if (LogManager.getLogManager() != CustomLogManager.INSTANCE) {
         throw new RuntimeException(LogManager.getLogManager() + " not CustomLogManager");
    }

    CustomLogManager.checkLogger(CustomLogManagerTest.class.getName());
    CustomLogManager.checkLogger("org.foo.Foo");
    CustomLogManager.checkLogger("org.foo.bar.Foo", RESOURCE_BUNDLE);
    CustomLogManager.checkLogger(Logger.GLOBAL_LOGGER_NAME);
    CustomLogManager.checkLogger("");
    CustomLogManager.checkLogger("org.openjdk.core.logger", RESOURCE_BUNDLE);
}
 
Example 8
Source File: SourceClassName.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void writeLogRecords(PrintStream logps) throws Exception {
    PrintStream err = System.err;
    try {
        System.setErr(logps);

        Object[] params = new Object[] { new Long(1), "string"};
        PlatformLogger plog = PlatformLogger.getLogger("test.log.foo");
        plog.severe("Log message {0} {1}", (Object[]) params);

        // create a java.util.logging.Logger
        // now java.util.logging.Logger should be created for each platform logger
        Logger logger = Logger.getLogger("test.log.bar");
        logger.log(Level.SEVERE, "Log message {0} {1}", params);

        plog.severe("Log message {0} {1}", (Object[]) params);
    } finally {
        logps.flush();
        logps.close();
        System.setErr(err);
    }
}
 
Example 9
Source File: SimpleLogManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    String classname = System.getProperty("java.util.logging.manager");
    if (!classname.equals("SimpleLogManager")) {
        throw new RuntimeException("java.util.logging.manager not set");
    }

    Logger logger = Logger.getLogger(SimpleLogManager.class.getName());
    Logger.getLogger("org.foo.bar.Foo");

    // a platform logger used by the system code is just a Logger instance.
    PlatformLogger.getLogger("org.openjdk.core.logger");

    LogManager mgr = LogManager.getLogManager();
    if (mgr != CustomLogManager.INSTANCE || !(mgr instanceof SimpleLogManager)) {
         throw new RuntimeException(LogManager.getLogManager() + " not SimpleLogManager");
    }

    checkCustomLogger(SimpleLogManager.class.getName(), null);
    checkCustomLogger("org.foo.bar.Foo", null);
    checkCustomLogger("org.openjdk.core.logger", "sun.util.logging.resources.logging");

    // ## The LogManager.demandLogger method does not handle custom log manager
    // ## that overrides the getLogger method to return a custom logger
    // ## (see the test case in 8005640).  Logger.getLogger may return
    // ## a Logger instance but LogManager overrides it with a custom Logger
    // ## instance like this case.
    //
    // However, the specification of LogManager and Logger subclassing is
    // not clear whether this is supported or not.  The following check
    // just captures the current behavior.
    if (logger instanceof CustomLogger) {
        throw new RuntimeException(logger + " not CustomLogger");
    }
}
 
Example 10
Source File: PlatformLoggerTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    final String FOO_PLATFORM_LOGGER = "test.platformlogger.foo";
    final String BAR_PLATFORM_LOGGER = "test.platformlogger.bar";
    final String GOO_PLATFORM_LOGGER = "test.platformlogger.goo";
    final String BAR_LOGGER = "test.logger.bar";
    PlatformLogger goo = PlatformLogger.getLogger(GOO_PLATFORM_LOGGER);
    // test the PlatformLogger methods
    testLogMethods(goo);

    // Create a platform logger using the default
    PlatformLogger foo = PlatformLogger.getLogger(FOO_PLATFORM_LOGGER);
    checkPlatformLogger(foo, FOO_PLATFORM_LOGGER);

    // create a java.util.logging.Logger
    // now java.util.logging.Logger should be created for each platform logger
    Logger logger = Logger.getLogger(BAR_LOGGER);
    logger.setLevel(Level.WARNING);

    PlatformLogger bar = PlatformLogger.getLogger(BAR_PLATFORM_LOGGER);
    checkPlatformLogger(bar, BAR_PLATFORM_LOGGER);

    // test the PlatformLogger methods
    testLogMethods(goo);
    testLogMethods(bar);

    checkLogger(FOO_PLATFORM_LOGGER, Level.FINER);
    checkLogger(BAR_PLATFORM_LOGGER, Level.FINER);

    checkLogger(GOO_PLATFORM_LOGGER, null);
    checkLogger(BAR_LOGGER, Level.WARNING);

    foo.setLevel(PlatformLogger.Level.SEVERE);
    checkLogger(FOO_PLATFORM_LOGGER, Level.SEVERE);

    checkPlatformLoggerLevels(foo, bar);
}
 
Example 11
Source File: DefaultPlatformLoggerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void test(LoggerFinder provider, boolean hasRequiredPermissions,
        java.util.logging.Logger appSink, java.util.logging.Logger sysSink) throws Exception {

    // No way to give a resource bundle to a platform logger.
    // ResourceBundle loggerBundle = ResourceBundle.getBundle(MyLoggerBundle.class.getName());
    final Map<PlatformLogger, String> loggerDescMap = new HashMap<>();

    PlatformLogger platform = PlatformLogger.getLogger("foo");
    loggerDescMap.put(platform, "PlatformLogger.getLogger(\"foo\")");

    testLogger(provider, loggerDescMap, "foo", null, platform, sysSink);
}
 
Example 12
Source File: WindowsPreferences.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static synchronized PlatformLogger logger() {
    if (logger == null) {
        logger = PlatformLogger.getLogger("java.util.prefs");
    }
    return logger;
}
 
Example 13
Source File: WindowsPreferences.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
private static synchronized PlatformLogger logger() {
    if (logger == null) {
        logger = PlatformLogger.getLogger("java.util.prefs");
    }
    return logger;
}
 
Example 14
Source File: LocaleServiceProviderPool.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void config(Class<? extends Object> caller, String message) {
    PlatformLogger logger = PlatformLogger.getLogger(caller.getCanonicalName());
    logger.config(message);
}
 
Example 15
Source File: LocaleServiceProviderPool.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void config(Class<? extends Object> caller, String message) {
    PlatformLogger logger = PlatformLogger.getLogger(caller.getCanonicalName());
    logger.config(message);
}
 
Example 16
Source File: PlatformLoggerTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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);

    }
}
 
Example 17
Source File: Utils.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private synchronized PlatformLogger getLogger() {
    if (log == null) {
        log = PlatformLogger.getLogger(name);
    }
    return log;
}
 
Example 18
Source File: FileSystemPreferences.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns logger for error messages. Backing store exceptions are logged at
 * WARNING level.
 */
private static PlatformLogger getLogger() {
    return PlatformLogger.getLogger("java.util.prefs");
}
 
Example 19
Source File: FileSystemPreferences.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns logger for error messages. Backing store exceptions are logged at
 * WARNING level.
 */
private static PlatformLogger getLogger() {
    return PlatformLogger.getLogger("java.util.prefs");
}
 
Example 20
Source File: FileSystemPreferences.java    From jdk-1.7-annotated with Apache License 2.0 2 votes vote down vote up
/**
 * Returns logger for error messages. Backing store exceptions are logged at
 * WARNING level.
 */
private static PlatformLogger getLogger() {
    return PlatformLogger.getLogger("java.util.prefs");
}