use of com.sun.identity.log.s1is.LogConfigReader in project OpenAM by OpenRock.
the class LogManager method readConfiguration.
/**
* This method overrides the <code>readConfiguration</code> method in
* JDK <code>LogManager</code> class.
* The base class method resets the loggers in memory. This method
* must add handlers to the loggers in memory according to the
* new configuration.
*
* @throws IOException if there are IO problems reading the configuration.
* @throws SecurityException if a security manager exists and if the caller
* does not have <code>LoggingPermission("control")</code>.
*/
public final void readConfiguration() throws IOException, SecurityException {
String[] xlogData = null;
try {
/*
* This writeLock ensures that no logging threads will execute
* a logger.log call after this point since they request for
* a readLock.
*/
Logger.rwLock.writeRequest();
/*
* This sync is for avoiding this thread snathing away
* time slice from a thread executing getLogger() method
* which is also sync on Logger.class
* which may lead to two handlers being added to the same logger.
*/
synchronized (Logger.class) {
Enumeration loggerNames = getLoggerNames();
LogManagerUtil.setupEnv();
if (didFirstReadConfig && SystemProperties.isServerMode()) {
oldLocation = getProperty(LogConstants.LOG_LOCATION);
oldLevel = getProperty(LogConstants.LOGGING_LEVEL);
oldSecurityStatus = getProperty(LogConstants.SECURITY_STATUS);
oldBackend = getProperty(LogConstants.BACKEND);
oldStatus = getProperty(LogConstants.LOG_STATUS_ATTR);
}
try {
/*
* This change is done for deploying AM as a single
* war. In server mode we will always use our
* LogConfigReader. On the client side the
* the JVM property will define whether to use the
* LogConfigReader or the remote handlers. If no
* JVM property is set, the remote handlers will
* be used.
*/
if (SystemProperties.isServerMode()) {
LogConfigReader logConfigReader = new LogConfigReader();
} else {
super.readConfiguration();
}
didFirstReadConfig = true;
} catch (Exception ex) {
/* no debug since our debugging system is not up. */
} finally {
LogManagerUtil.resetEnv();
}
if (isLocal) {
securityStatus = false;
readAllFields();
readSelectedFieldSet();
if (SystemProperties.isServerMode()) {
newLocation = getProperty(LogConstants.LOG_LOCATION);
newLevel = getProperty(LogConstants.LOGGING_LEVEL);
newSecurityStatus = getProperty(LogConstants.SECURITY_STATUS);
newBackend = getProperty(LogConstants.BACKEND);
newStatus = getProperty(LogConstants.LOG_STATUS_ATTR);
}
/*
* give all the pertinent values to decide why
* logging to the file was terminated. still
* have to check that one of the attributes
* that changed would cause a "real" termination
* of logging to the files/tables in the current
* location (as opposed to just a buffer timer change,
* for instance).
*/
String[] logData = { oldLocation, newLocation, oldBackend, newBackend, oldSecurityStatus, newSecurityStatus, oldStatus, newStatus, oldLevel, newLevel };
if (getProperty(LogConstants.BACKEND).equals("DB")) {
HANDLER = getProperty(LogConstants.DB_HANDLER);
FORMATTER = getProperty(LogConstants.DB_FORMATTER);
String driver = getProperty(LogConstants.DB_DRIVER);
} else if (getProperty(LogConstants.BACKEND).equals("Syslog")) {
HANDLER = getProperty(LogConstants.SYSLOG_HANDLER);
FORMATTER = getProperty(LogConstants.SYSLOG_FORMATTER);
} else if (getProperty(LogConstants.SECURITY_STATUS).equalsIgnoreCase("ON")) {
securityStatus = true;
HANDLER = getProperty(LogConstants.SECURE_FILE_HANDLER);
FORMATTER = getProperty(LogConstants.SECURE_ELF_FORMATTER);
} else {
HANDLER = getProperty(LogConstants.FILE_HANDLER);
FORMATTER = getProperty(LogConstants.ELF_FORMATTER);
}
if (getProperty(LogConstants.BACKEND).equals("File")) {
if (SystemProperties.isServerMode() && (newLocation != null) && (oldLocation != null) && !oldLocation.equals(newLocation)) {
File dir = new File(newLocation);
if (!dir.exists()) {
if (!dir.mkdirs()) {
Debug.error("LogManager:readConfiguration:" + "Unable to create the new log " + "directory. Verify that the " + "process has necessary permissions");
}
}
}
}
boolean loggingInactive = (getProperty(LogConstants.LOG_STATUS_ATTR).equals(inactive));
String strLogLevel = getProperty(LogConstants.LOGGING_LEVEL);
try {
loggingLevel = Level.parse(strLogLevel);
} catch (IllegalArgumentException iaex) {
// default
loggingLevel = Level.INFO;
Debug.error("LogManager:readConfiguration:" + "Log level '" + strLogLevel + "' unknown; setting to Level.INFO.");
}
if (loggingInactive) {
loggingLevel = Level.OFF;
}
xlogData = logData;
} else {
HANDLER = getProperty(LogConstants.REMOTE_HANDLER);
if (HANDLER == null) {
HANDLER = LogConstants.DEFAULT_REMOTE_HANDER;
}
FORMATTER = getProperty(LogConstants.REMOTE_FORMATTER);
if (FORMATTER == null) {
FORMATTER = LogConstants.DEFAULT_REMOTE_FORMATTER;
}
}
Logger.resolveHostName = Boolean.valueOf(getProperty(LogConstants.LOG_RESOLVE_HOSTNAME_ATTR)).booleanValue();
/*
* modify existing loggers in memory according
* to the new configuration
*/
loggerNames = getLoggerNames();
while (loggerNames.hasMoreElements()) {
String curEl = (String) loggerNames.nextElement();
/* avoid root logger */
if (!curEl.isEmpty() && !curEl.equals("global")) {
if (Debug.messageEnabled()) {
Debug.message("LogManager:readConfiguration:" + "Processing Logger: " + curEl);
}
/*
* remove all handlers and add new handlers for
* this logger
*/
Logger l = (Logger) Logger.getLogger(curEl);
Handler[] handlers = l.getHandlers();
for (int i = 0; i < handlers.length; i++) {
handlers[i].close();
l.removeHandler(handlers[i]);
}
String handlerClass = LogManager.HANDLER;
Class clz = null;
Class[] parameters = { String.class };
Object[] parameterObjects = { l.getName() };
Constructor cons = null;
Handler h = null;
try {
clz = Class.forName(handlerClass);
} catch (Exception e) {
Debug.error("LogManager.readConfiguration:could not load " + handlerClass, e);
}
try {
cons = clz.getDeclaredConstructor(parameters);
} catch (Exception e) {
Debug.error("LogManager.readConfiguration:could not" + " instantiate" + handlerClass, e);
}
try {
h = (Handler) cons.newInstance(parameterObjects);
} catch (Exception e) {
Debug.error("LogManager.readConfiguration:could not" + " instantiate" + handlerClass, e);
}
String formatterClass = LogManager.FORMATTER;
Formatter f = null;
try {
f = (Formatter) Class.forName(formatterClass).newInstance();
} catch (Exception e) {
Debug.error("LogManager.readConfiguration:could not" + " instantiate Formatter " + formatterClass, e);
}
h.setFormatter(f);
l.addHandler(h);
/*
* get the "iplanet-am-logging.<logfilename>.level
* value for this file, if it's been added on the
* server's advanced config page.
*
* BUT: logging status set to Inactive means
* all logging is turned Level.OFF
*/
Level tlevel = loggingLevel;
if (loggingLevel != Level.OFF) {
String levelProp = LogConstants.LOG_PROP_PREFIX + "." + l.getName() + ".level";
String lvlStr = SystemProperties.get(levelProp);
if ((lvlStr != null) && (lvlStr.length() > 0)) {
try {
tlevel = Level.parse(lvlStr);
} catch (IllegalArgumentException iaex) {
// use value for all others
}
}
}
if (loggingLevel != null) {
// only if isLocal
// update logging level
l.setLevel(tlevel);
}
}
/* end of avoid rootlogger */
}
/* end of while(loggerNames.hasMoreElements) */
}
/* end of synchronized(Logger.class) */
} finally {
Logger.rwLock.writeDone();
}
if (SystemProperties.isServerMode() && isLocal) {
checkStartLogs(xlogData);
//Update the new configuration info in Monitoring handle also
updateMonitConfigForLogService();
}
}
Aggregations