org.ajax4jsf.framework.ajax.xmlfilter.Log4JConfigurator Maven / Gradle / Ivy
/**
* Licensed under the Common Development and Distribution License,
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.sun.com/cddl/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.ajax4jsf.framework.ajax.xmlfilter;
import java.util.Properties;
import org.ajax4jsf.framework.util.message.Messages;
import org.apache.log4j.LogManager;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.xml.DOMConfigurator;
/**
* @author shura (latest modification by $Author: slava_kabanovich $)
* @version $Revision: 1.2 $ $Date: 2006/07/11 15:54:51 $
*
*/
class Log4JConfigurator {
private static final String CONTEXT_ROOT_VARIABLE = "context-root";
private Properties props = new Properties();
private String prefix;
DOMConfigurator domConfig;
void doConfigure(String file){
domConfig.doConfigure(prefix + file, LogManager.getLoggerRepository());
}
/**
* @param prefix
*/
public Log4JConfigurator(String prefix) {
this.prefix = prefix;
props.setProperty(CONTEXT_ROOT_VARIABLE, prefix);
domConfig = new DOMConfigurator() {
/*
* (non-Javadoc)
*
* @see org.apache.log4j.xml.DOMConfigurator#subst(java.lang.String)
* append context-related properties for variable
* substitution.
*/
protected String subst(String value) {
try {
return OptionConverter.substVars(value, props);
} catch (IllegalArgumentException e) {
LogLog.warn(Messages.getMessage(Messages.VARIABLE_SUBSTITUTION_WARNING), e);
return value;
}
};
};
}
}