30 import java.security.PrivilegedAction; |
30 import java.security.PrivilegedAction; |
31 import java.util.ResourceBundle; |
31 import java.util.ResourceBundle; |
32 import java.util.function.Supplier; |
32 import java.util.function.Supplier; |
33 import java.lang.System.LoggerFinder; |
33 import java.lang.System.LoggerFinder; |
34 import java.lang.System.Logger; |
34 import java.lang.System.Logger; |
|
35 import java.lang.reflect.Module; |
35 import java.util.Objects; |
36 import java.util.Objects; |
36 import java.util.logging.LogManager; |
37 import java.util.logging.LogManager; |
37 import jdk.internal.logger.DefaultLoggerFinder; |
38 import jdk.internal.logger.DefaultLoggerFinder; |
38 import java.util.logging.LoggingPermission; |
39 import java.util.logging.LoggingPermission; |
39 import sun.util.logging.PlatformLogger; |
40 import sun.util.logging.PlatformLogger; |
396 |
397 |
397 |
398 |
398 } |
399 } |
399 |
400 |
400 /** |
401 /** |
401 * Creates a java.util.logging.Logger for the given caller. |
402 * Creates a java.util.logging.Logger for the given module. |
402 * @param name the logger name. |
403 * @param name the logger name. |
403 * @param caller the caller for which the logger should be created. |
404 * @param module the module for which the logger should be created. |
404 * @return a Logger suitable for use in the given caller. |
405 * @return a Logger suitable for use in the given module. |
405 */ |
406 */ |
406 private static java.util.logging.Logger demandJULLoggerFor(final String name, |
407 private static java.util.logging.Logger demandJULLoggerFor(final String name, |
407 /* Module */ |
408 Module module) { |
408 final Class<?> caller) { |
|
409 final LogManager manager = LogManager.getLogManager(); |
409 final LogManager manager = LogManager.getLogManager(); |
410 final SecurityManager sm = System.getSecurityManager(); |
410 final SecurityManager sm = System.getSecurityManager(); |
411 if (sm == null) { |
411 if (sm == null) { |
412 return logManagerAccess.demandLoggerFor(manager, name, caller); |
412 return logManagerAccess.demandLoggerFor(manager, name, module); |
413 } else { |
413 } else { |
414 final PrivilegedAction<java.util.logging.Logger> pa = |
414 final PrivilegedAction<java.util.logging.Logger> pa = |
415 () -> logManagerAccess.demandLoggerFor(manager, name, caller); |
415 () -> logManagerAccess.demandLoggerFor(manager, name, module); |
416 return AccessController.doPrivileged(pa, null, LOGGING_CONTROL_PERMISSION); |
416 return AccessController.doPrivileged(pa, null, LOGGING_CONTROL_PERMISSION); |
417 } |
417 } |
418 } |
418 } |
419 |
419 |
420 /** |
420 /** |
427 * @return {@inheritDoc} |
427 * @return {@inheritDoc} |
428 * @throws SecurityException if the calling code doesn't have the |
428 * @throws SecurityException if the calling code doesn't have the |
429 * {@code RuntimePermission("loggerFinder")}. |
429 * {@code RuntimePermission("loggerFinder")}. |
430 */ |
430 */ |
431 @Override |
431 @Override |
432 protected Logger demandLoggerFor(String name, /* Module */ Class<?> caller) { |
432 protected Logger demandLoggerFor(String name, Module module) { |
433 final SecurityManager sm = System.getSecurityManager(); |
433 final SecurityManager sm = System.getSecurityManager(); |
434 if (sm != null) { |
434 if (sm != null) { |
435 sm.checkPermission(LOGGERFINDER_PERMISSION); |
435 sm.checkPermission(LOGGERFINDER_PERMISSION); |
436 } |
436 } |
437 return JULWrapper.of(demandJULLoggerFor(name,caller)); |
437 return JULWrapper.of(demandJULLoggerFor(name,module)); |
438 } |
438 } |
439 |
439 |
440 public static interface LogManagerAccess { |
440 public static interface LogManagerAccess { |
441 java.util.logging.Logger demandLoggerFor(LogManager manager, |
441 java.util.logging.Logger demandLoggerFor(LogManager manager, |
442 String name, /* Module */ Class<?> caller); |
442 String name, Module module); |
443 } |
443 } |
444 |
444 |
445 // Hook for tests |
445 // Hook for tests |
446 public static LogManagerAccess getLogManagerAccess() { |
446 public static LogManagerAccess getLogManagerAccess() { |
447 final SecurityManager sm = System.getSecurityManager(); |
447 final SecurityManager sm = System.getSecurityManager(); |