BaseLogManagerpublic abstract class BaseLogManager extends LogManager Class BaseLogManager serves as an abstract base class for the Application
Client Container and Application Server loggers. The main purpose of
this class is to override the addLogger method which provides a hook
to attach custom handlers and formatters and to provide a default
resource bundle if none is provided. Note that providing a default resource
bundle somewhat alters the semantics of a Logger.getLogger(name) call
followed by a Logger.getLogger(name, resourcebundle) call. With the
BaseHandler installed, the later call will have no effect as the call to
Logger.getLogger(name) implicitely defines a resource bundle. |
Fields Summary |
---|
private boolean | _configurationRead | private List | _unInitializedLoggers | private Boolean | mogLoggerCreated | protected static Logger | _logger |
Constructors Summary |
---|
protected BaseLogManager()
// WARNING: This is here to force static initialization of IASLevel.
// This is necessary so that Level.parse() can interpret the new
// statically initialized IASLevel constants without throwing an
// IllegalArgumentException
IASLevel.ALERT.getName();
super();
|
Methods Summary |
---|
public boolean | addLogger(java.util.logging.Logger logger)
String modLoggerName = ModuleToLoggerNameMapper.getMatchedModuleLoggerName(logger.getName());
if (modLoggerName !=null && !modLoggerName.equals(logger.getName())) {
Logger.getLogger(modLoggerName); //will results in recursive call to this method.
}
// The first call to initializeLogger may have a null _logger.
boolean result = super.addLogger(logger);
// result will be true if the logger does not exist already
if (result) {
try {
// The first logger created becomes the logger that we will
// use internally to log.
if (_logger == null) {
_logger = logger;
}
// Defer initialization until the configuration (e.g. logging.properties) is
// read. Once the configuration is read we go back and re-initialize any
// loggers that were created prior to the configuration being read.
synchronized (_unInitializedLoggers) {
if (!_configurationRead) {
_unInitializedLoggers.add(logger);
return result;
} else {
doInitializeLogger(logger);
}
}
} catch (Throwable th) {
th.printStackTrace();
_logger.log(Level.SEVERE, "addLogger exception ", th);
}
}
return result;
| protected void | doInitializeLogger(java.util.logging.Logger logger)
String loggerName = logger.getName( );
// We don't want to associate a Log Resource Bundle to org.apache or
// tomcat loggers.
// _REVISIT_: Clean this code not set any resource bundle in future,
// because resource bundles should be associated by the modules itself
if(! ( ( loggerName.startsWith( "org.apache" ) )
|| ( loggerName.startsWith( "com.sun.faces" ) )
|| ( loggerName.startsWith( "tomcat" ) ) ) )
{
// This is tricky. If the logger was not created with a resource
// bundle, we want to re-create it (to provide it with our default
// resource bundle name); however, due to implementation details in
// Logger.getLogger(name, resourceBundleName), we should get back
// the same instance
if (logger.getResourceBundleName() == null) {
try {
Logger newLogger =
Logger.getLogger(logger.getName(),
getLoggerResourceBundleName(logger.getName()));
assert(logger == newLogger);
} catch (Throwable ex) {
// This exception is intentionally eaten. It indicates
// that the default resource bundle (specified by
// getLoggerResourceBundleName) does not exist.
// Logger is already created.
}
}
}
// Finally call the real initialization
initializeLogger(logger);
| public java.lang.String | getLoggerResourceBundleName(java.lang.String loggerName)
String result = loggerName + "." + LogDomains.RESOURCE_BUNDLE;
return result.replaceFirst(LogDomains.DOMAIN_ROOT,
LogDomains.PACKAGE_ROOT);
| protected abstract void | initializeLogger(java.util.logging.Logger logger)
| public void | readConfiguration(java.io.InputStream ins)
super.readConfiguration(ins);
synchronized (_unInitializedLoggers) {
_configurationRead = true;
Iterator iter = _unInitializedLoggers.iterator();
while (iter.hasNext()) {
Logger l = (Logger)iter.next();
doInitializeLogger(l);
}
_unInitializedLoggers.clear();
}
|
|