提交 f91f21c6 编写于 作者: D dfuchs

8029740: Enhance handling of loggers

Reviewed-by: mchung, ahgross
上级 b746c767
......@@ -548,7 +548,7 @@ public class LogManager {
Logger result = getLogger(name);
if (result == null) {
// only allocate the new logger once
Logger newLogger = new Logger(name, resourceBundleName, caller, this);
Logger newLogger = new Logger(name, resourceBundleName, caller, this, false);
do {
if (addLogger(newLogger)) {
// We successfully added the new Logger that we
......@@ -595,13 +595,13 @@ public class LogManager {
} while (logger == null);
// LogManager will set the sysLogger's handlers via LogManager.addLogger method.
if (logger != sysLogger && sysLogger.getHandlers().length == 0) {
if (logger != sysLogger && sysLogger.accessCheckedHandlers().length == 0) {
// if logger already exists but handlers not set
final Logger l = logger;
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
for (Handler hdl : l.getHandlers()) {
for (Handler hdl : l.accessCheckedHandlers()) {
sysLogger.addHandler(hdl);
}
return null;
......@@ -919,7 +919,7 @@ public class LogManager {
Logger result = findLogger(name);
if (result == null) {
// only allocate the new system logger once
Logger newLogger = new Logger(name, resourceBundleName, null, getOwner());
Logger newLogger = new Logger(name, resourceBundleName, null, getOwner(), true);
do {
if (addLocalLogger(newLogger)) {
// We successfully added the new Logger that we
......@@ -1637,7 +1637,7 @@ public class LogManager {
// We do not call the protected Logger two args constructor here,
// to avoid calling LogManager.getLogManager() from within the
// RootLogger constructor.
super("", null, null, LogManager.this);
super("", null, null, LogManager.this, true);
setLevel(defaultLevel);
}
......@@ -1661,9 +1661,9 @@ public class LogManager {
}
@Override
public Handler[] getHandlers() {
Handler[] accessCheckedHandlers() {
initializeGlobalHandlers();
return super.getHandlers();
return super.accessCheckedHandlers();
}
}
......
......@@ -277,6 +277,7 @@ public class Logger {
private volatile Level levelObject;
private volatile int levelValue; // current effective level value
private WeakReference<ClassLoader> callersClassLoaderRef;
private final boolean isSystemLogger;
/**
* GLOBAL_LOGGER_NAME is a name for the global logger.
......@@ -370,11 +371,12 @@ public class Logger {
* no corresponding resource can be found.
*/
protected Logger(String name, String resourceBundleName) {
this(name, resourceBundleName, null, LogManager.getLogManager());
this(name, resourceBundleName, null, LogManager.getLogManager(), false);
}
Logger(String name, String resourceBundleName, Class<?> caller, LogManager manager) {
Logger(String name, String resourceBundleName, Class<?> caller, LogManager manager, boolean isSystemLogger) {
this.manager = manager;
this.isSystemLogger = isSystemLogger;
setupResourceInfo(resourceBundleName, caller);
this.name = name;
levelValue = Level.INFO.intValue();
......@@ -401,6 +403,7 @@ public class Logger {
private Logger(String name) {
// The manager field is not initialized here.
this.name = name;
this.isSystemLogger = true;
levelValue = Level.INFO.intValue();
}
......@@ -635,7 +638,7 @@ public class Logger {
// cleanup some Loggers that have been GC'ed
manager.drainLoggerRefQueueBounded();
Logger result = new Logger(null, resourceBundleName,
Reflection.getCallerClass(), manager);
Reflection.getCallerClass(), manager, false);
result.anonymous = true;
Logger root = manager.getLogger("");
result.doSetParent(root);
......@@ -727,15 +730,23 @@ public class Logger {
Logger logger = this;
while (logger != null) {
for (Handler handler : logger.getHandlers()) {
final Handler[] loggerHandlers = isSystemLogger
? logger.accessCheckedHandlers()
: logger.getHandlers();
for (Handler handler : loggerHandlers) {
handler.publish(record);
}
if (!logger.getUseParentHandlers()) {
final boolean useParentHdls = isSystemLogger
? logger.useParentHandlers
: logger.getUseParentHandlers();
if (!useParentHdls) {
break;
}
logger = logger.getParent();
logger = isSystemLogger ? logger.parent : logger.getParent();
}
}
......@@ -1762,6 +1773,12 @@ public class Logger {
* @return an array of all registered Handlers
*/
public Handler[] getHandlers() {
return accessCheckedHandlers();
}
// This method should ideally be marked final - but unfortunately
// it needs to be overridden by LogManager.RootLogger
Handler[] accessCheckedHandlers() {
return handlers.toArray(emptyHandlers);
}
......@@ -2150,12 +2167,14 @@ public class Logger {
if (trb.userBundle != null) {
return trb;
}
final String rbName = target.getResourceBundleName();
final String rbName = isSystemLogger
? trb.resourceBundleName
: target.getResourceBundleName();
if (rbName != null) {
return LoggerBundle.get(rbName,
findResourceBundle(rbName, true));
}
target = target.getParent();
target = isSystemLogger ? target.parent : target.getParent();
}
return NO_RESOURCE_BUNDLE;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册