Logger logger = (Logger) loggers.nextElement();
if (logger.getLevel() != null) {
addAppendersToSet(logger.getAllAppenders(), appenderSet);
}
}
Appender appender = null;
for (Iterator<Appender> iter = appenderSet.iterator(); iter.hasNext();) {
appender = iter.next();
if (appender.getName().equals(appenderName)) {
break;
}
}
if (appender != null) {
if (appender instanceof FileAppender) {
isFileAppender = true;
} else if (appender instanceof SyslogAppender) {
isSysLogAppender = true;
}
//Registry operations are performed before updating the actual appender in the memory
if (isFileAppender) {
//TODO add syslogPattern to appenderPattern
appenderPattern = addSyslogPattern(appenderPattern);
// Check if the file is valid
logFileName = logFileName.replace('\\', '/');
File logFile = new File(logFileName);
if (!logFile.isAbsolute()) {
if (logFileName.startsWith("./")) {
logFileName = logFileName.substring(2);
}
logFileName = (System.getProperty(ServerConstants.CARBON_HOME) + "/" +
logFileName).replace('\\', '/');
logFile = new File(logFileName);
}
if (!logFile.exists()) {
int lastIndex = logFileName.lastIndexOf("/");
String msg = "Cannot create logfile " + logFileName +
". Please verify that the logging directory exists, log file name is " +
"valid and that you have read-write access to this file.";
if (lastIndex != -1) {
String dirName = logFileName.substring(0, lastIndex);
File dir = new File(dirName);
if (!dir.exists() && !dir.mkdirs()) {
throw new Exception(msg);
}
}
try {
if (!logFile.createNewFile()) {
throw new Exception(msg);
}
} catch (IOException e) {
throw new Exception(msg);
}
}
if (persist) {
registryManager.updateAppender(appender, appenderName, appenderPattern, threshold,
logFileName, null, null, true, false);
}
} else if (isSysLogAppender) {
if (persist) {
registryManager.updateAppender(appender, appenderName, appenderPattern, threshold,
null, sysLogHost, facility, false, true);
}
} else {
if (persist) {
registryManager.updateAppender(appender, appenderName, appenderPattern, threshold,
null, null, null, false, false);
}
}
if ((appender.getLayout() != null) &&
(appender.getLayout() instanceof PatternLayout)) {
((PatternLayout) appender.getLayout()).setConversionPattern(appenderPattern);
}
if (appender instanceof FileAppender) {
((FileAppender) appender).setFile(logFileName);
if (LoggingAdmin.log.isDebugEnabled()) {
LoggingAdmin.log.debug("change the logfile of the appender ==> " +
appender.getName() + " to " + logFileName);
}
((FileAppender) appender).activateOptions();
}
if (appender instanceof SyslogAppender) {