< prev index next >

jdk/src/java.logging/share/classes/java/util/logging/LogManager.java

Print this page

        

*** 41,50 **** --- 41,51 ---- import java.util.stream.Collectors; import java.util.stream.Stream; import jdk.internal.misc.JavaAWTAccess; import jdk.internal.misc.SharedSecrets; import sun.misc.ManagedLocalsThread; + import sun.util.logging.internal.LoggingProviderImpl; /** * There is a single global LogManager object that is used to * maintain a set of shared state about Loggers and log services. * <p>
*** 434,444 **** readPrimordialConfiguration = true; try { readConfiguration(); // Platform loggers begin to delegate to java.util.logging.Logger ! sun.util.logging.PlatformLogger.redirectPlatformLoggers(); } catch (Exception ex) { assert false : "Exception raised while reading logging configuration: " + ex; } } } --- 435,446 ---- readPrimordialConfiguration = true; try { readConfiguration(); // Platform loggers begin to delegate to java.util.logging.Logger ! jdk.internal.logger.BootstrapLogger.redirectTemporaryLoggers(); ! } catch (Exception ex) { assert false : "Exception raised while reading logging configuration: " + ex; } } }
*** 1479,1489 **** * Reads and initializes the logging configuration from the given input stream. * * <p> * Any {@linkplain #addConfigurationListener registered configuration * listener} will be invoked after the properties are read. ! * <p> * @apiNote This {@code readConfiguration} method should only be used for * initializing the configuration during LogManager initialization or * used with the "java.util.logging.config.class" property. * When this method is called after loggers have been created, all * existing loggers will be {@linkplain #reset() reset}. Then any --- 1481,1491 ---- * Reads and initializes the logging configuration from the given input stream. * * <p> * Any {@linkplain #addConfigurationListener registered configuration * listener} will be invoked after the properties are read. ! * * @apiNote This {@code readConfiguration} method should only be used for * initializing the configuration during LogManager initialization or * used with the "java.util.logging.config.class" property. * When this method is called after loggers have been created, all * existing loggers will be {@linkplain #reset() reset}. Then any
*** 2361,2371 **** } finally { configurationLock.unlock(); } } ! static final Permission controlPermission = new LoggingPermission("control", null); void checkPermission() { SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPermission(controlPermission); --- 2363,2374 ---- } finally { configurationLock.unlock(); } } ! static final Permission controlPermission = ! new LoggingPermission("control", null); void checkPermission() { SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPermission(controlPermission);
*** 2605,2610 **** --- 2608,2678 ---- // after all listeners have been invoked. if (t instanceof Error) throw (Error)t; if (t instanceof RuntimeException) throw (RuntimeException)t; } + /** + * This class allows the {@link LoggingProviderImpl} to demand loggers on + * behalf of system and application classes. + */ + private static final class LoggingProviderAccess + implements LoggingProviderImpl.LogManagerAccess, + PrivilegedAction<Void> { + + private LoggingProviderAccess() { + } + + /** + * Demands a logger on behalf of the given {@code caller}. + * <p> + * If a named logger suitable for the given caller is found + * returns it. + * Otherwise, creates a new logger suitable for the given caller. + * + * @param name The logger name. + * @param caller The caller on which behalf the logger is created/retrieved. + * @return A logger for the given {@code caller}. + * + * @throws NullPointerException if {@code name} is {@code null} + * or {@code caller} is {@code null}. + * @throws IllegalArgumentException if {@code manager} is not the default + * LogManager. + * @throws SecurityException if a security manager is present and the + * calling code doesn't have the + * {@link LoggingPermission LoggingPermission("demandLogger", null)}. + */ + @Override + public Logger demandLoggerFor(LogManager manager, String name, /* Module */ Class<?> caller) { + if (manager != getLogManager()) { + // having LogManager as parameter just ensures that the + // caller will have initialized the LogManager before reaching + // here. + throw new IllegalArgumentException("manager"); + } + Objects.requireNonNull(name); + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(controlPermission); + } + if (caller.getClassLoader() == null) { + return manager.demandSystemLogger(name, + Logger.SYSTEM_LOGGER_RB_NAME, caller); + } else { + return manager.demandLogger(name, null, caller); + } + } + + @Override + public Void run() { + LoggingProviderImpl.setLogManagerAccess(INSTANCE); + return null; + } + + static final LoggingProviderAccess INSTANCE = new LoggingProviderAccess(); + } + + static { + AccessController.doPrivileged(LoggingProviderAccess.INSTANCE, null, + controlPermission); + } + }
< prev index next >