< prev index next >
src/java.logging/share/classes/java/util/logging/LogManager.java
Print this page
*** 42,51 ****
--- 42,53 ----
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;
+ import java.lang.reflect.Module;
+ import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
/**
* There is a single global LogManager object that is used to
* maintain a set of shared state about Loggers and log services.
* <p>
*** 501,514 ****
// This method must delegate to the LogManager implementation to
// add a new Logger or return the one that has been added previously
// as a LogManager subclass may override the addLogger, getLogger,
// readConfiguration, and other methods.
Logger demandLogger(String name, String resourceBundleName, Class<?> caller) {
Logger result = getLogger(name);
if (result == null) {
// only allocate the new logger once
! Logger newLogger = new Logger(name, resourceBundleName, caller, this, false);
do {
if (addLogger(newLogger)) {
// We successfully added the new Logger that we
// created above so return it without refetching.
return newLogger;
--- 503,522 ----
// This method must delegate to the LogManager implementation to
// add a new Logger or return the one that has been added previously
// as a LogManager subclass may override the addLogger, getLogger,
// readConfiguration, and other methods.
Logger demandLogger(String name, String resourceBundleName, Class<?> caller) {
+ final Module module = caller == null ? null : caller.getModule();
+ return demandLogger(name, resourceBundleName, module);
+ }
+
+ Logger demandLogger(String name, String resourceBundleName, Module module) {
Logger result = getLogger(name);
if (result == null) {
// only allocate the new logger once
! Logger newLogger = new Logger(name, resourceBundleName,
! module == null ? null : module, this, false);
do {
if (addLogger(newLogger)) {
// We successfully added the new Logger that we
// created above so return it without refetching.
return newLogger;
*** 530,542 ****
}
return result;
}
Logger demandSystemLogger(String name, String resourceBundleName, Class<?> caller) {
// Add a system logger in the system context's namespace
final Logger sysLogger = getSystemContext()
! .demandLogger(name, resourceBundleName, caller);
// Add the system logger to the LogManager's namespace if not exist
// so that there is only one single logger of the given name.
// System loggers are visible to applications unless a logger of
// the same name has been added.
--- 538,555 ----
}
return result;
}
Logger demandSystemLogger(String name, String resourceBundleName, Class<?> caller) {
+ final Module module = caller == null ? null : caller.getModule();
+ return demandSystemLogger(name, resourceBundleName, module);
+ }
+
+ Logger demandSystemLogger(String name, String resourceBundleName, Module module) {
// Add a system logger in the system context's namespace
final Logger sysLogger = getSystemContext()
! .demandLogger(name, resourceBundleName, module);
// Add the system logger to the LogManager's namespace if not exist
// so that there is only one single logger of the given name.
// System loggers are visible to applications unless a logger of
// the same name has been added.
*** 617,631 ****
@SuppressWarnings("deprecation") // avoids initialization cycles.
final Logger global = Logger.global;
return global;
}
! Logger demandLogger(String name, String resourceBundleName, Class<?> caller) {
// a LogManager subclass may have its own implementation to add and
// get a Logger. So delegate to the LogManager to do the work.
final LogManager owner = getOwner();
! return owner.demandLogger(name, resourceBundleName, caller);
}
// Due to subtle deadlock issues getUserContext() no longer
// calls addLocalLogger(rootLogger);
--- 630,644 ----
@SuppressWarnings("deprecation") // avoids initialization cycles.
final Logger global = Logger.global;
return global;
}
! Logger demandLogger(String name, String resourceBundleName, Module module) {
// a LogManager subclass may have its own implementation to add and
// get a Logger. So delegate to the LogManager to do the work.
final LogManager owner = getOwner();
! return owner.demandLogger(name, resourceBundleName, module);
}
// Due to subtle deadlock issues getUserContext() no longer
// calls addLocalLogger(rootLogger);
*** 905,919 ****
// Add a system logger in the system context's namespace as well as
// in the LogManager's namespace if not exist so that there is only
// one single logger of the given name. System loggers are visible
// to applications unless a logger of the same name has been added.
@Override
! Logger demandLogger(String name, String resourceBundleName, Class<?> caller) {
Logger result = findLogger(name);
if (result == null) {
// only allocate the new system logger once
! Logger newLogger = new Logger(name, resourceBundleName, caller, getOwner(), true);
do {
if (addLocalLogger(newLogger)) {
// We successfully added the new Logger that we
// created above so return it without refetching.
result = newLogger;
--- 918,934 ----
// Add a system logger in the system context's namespace as well as
// in the LogManager's namespace if not exist so that there is only
// one single logger of the given name. System loggers are visible
// to applications unless a logger of the same name has been added.
@Override
! Logger demandLogger(String name, String resourceBundleName,
! Module module) {
Logger result = findLogger(name);
if (result == null) {
// only allocate the new system logger once
! Logger newLogger = new Logger(name, resourceBundleName,
! module, getOwner(), true);
do {
if (addLocalLogger(newLogger)) {
// We successfully added the new Logger that we
// created above so return it without refetching.
result = newLogger;
*** 2620,2665 ****
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() {
--- 2635,2681 ----
private LoggingProviderAccess() {
}
/**
! * Demands a logger on behalf of the given {@code module}.
* <p>
! * If a named logger suitable for the given module is found
* returns it.
! * Otherwise, creates a new logger suitable for the given module.
*
* @param name The logger name.
! * @param module The module on which behalf the logger is created/retrieved.
! * @return A logger for the given {@code module}.
*
* @throws NullPointerException if {@code name} is {@code null}
! * or {@code module} 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 module) {
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);
+ Objects.requireNonNull(module);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(controlPermission);
}
! if (isSystem(module)) {
return manager.demandSystemLogger(name,
! Logger.SYSTEM_LOGGER_RB_NAME, module);
} else {
! return manager.demandLogger(name, null, module);
}
}
@Override
public Void run() {
< prev index next >