< prev index next >

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

Print this page

        

@@ -437,11 +437,12 @@
             readPrimordialConfiguration = true;
             try {
                 readConfiguration();
 
                 // Platform loggers begin to delegate to java.util.logging.Logger
-                sun.util.logging.PlatformLogger.redirectPlatformLoggers();
+                sun.util.logger.BootstrapLogger.redirectTemporaryLoggers();
+
             } catch (Exception ex) {
                 assert false : "Exception raised while reading logging configuration: " + ex;
             }
         }
     }

@@ -1665,11 +1666,14 @@
         } finally {
             configurationLock.unlock();
         }
     }
 
-    static final Permission controlPermission = new LoggingPermission("control", null);
+    static final Permission controlPermission =
+            new LoggingPermission("control", null);
+    static final Permission demandLoggerPermission =
+            new LoggingPermission("demandLogger", null);
 
     void checkPermission() {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null)
             sm.checkPermission(controlPermission);

@@ -1909,6 +1913,34 @@
         // after all listeners have been invoked.
         if (t instanceof Error) throw (Error)t;
         if (t instanceof RuntimeException) throw (RuntimeException)t;
     }
 
+    /**
+     * Demands a logger suitable for given 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 caller.
+     *
+     * @throws SecurityException if the calling code doesn't have the
+     *        {@link LoggingPermission LoggingPermission("demandLogger", null)}.
+     * @since 9
+     */
+    public static Logger demandLoggerFor(String name, /* Module */ Class<?> caller) {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(demandLoggerPermission);
+        }
+        if (caller.getClassLoader() == null) {
+            return LogManager.getLogManager().demandSystemLogger(name,
+                Logger.SYSTEM_LOGGER_RB_NAME, caller);
+        } else {
+            return LogManager.getLogManager().demandLogger(name, null, caller);
+        }
+    }
+
 }
< prev index next >