001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.log4j.config;
019
020import org.apache.logging.log4j.core.LoggerContext;
021import org.apache.logging.log4j.core.config.Configuration;
022import org.apache.logging.log4j.core.config.ConfigurationFactory;
023import org.apache.logging.log4j.core.config.ConfigurationSource;
024import org.apache.logging.log4j.core.config.Order;
025import org.apache.logging.log4j.core.config.plugins.Plugin;
026import org.apache.logging.log4j.util.PropertiesUtil;
027
028/**
029 * Configures Log4j from a log4j 1 format properties file.
030 */
031@Plugin(name = "Log4j1PropertiesConfigurationFactory", category = ConfigurationFactory.CATEGORY)
032@Order(2)
033public class PropertiesConfigurationFactory extends ConfigurationFactory {
034
035    static final String FILE_EXTENSION = ".properties";
036
037    /**
038     * File name prefix for test configurations.
039     */
040    protected static final String TEST_PREFIX = "log4j-test";
041
042    /**
043     * File name prefix for standard configurations.
044     */
045    protected static final String DEFAULT_PREFIX = "log4j";
046
047    @Override
048    protected String[] getSupportedTypes() {
049        if (!PropertiesUtil.getProperties().getBooleanProperty(ConfigurationFactory.LOG4J1_EXPERIMENTAL, Boolean.FALSE)) {
050            return null;
051        }
052        return new String[] { FILE_EXTENSION };
053    }
054
055    @Override
056    public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
057        int interval = PropertiesUtil.getProperties().getIntegerProperty(Log4j1Configuration.MONITOR_INTERVAL, 0);
058        return new PropertiesConfiguration(loggerContext, source, interval);
059    }
060
061    @Override
062    protected String getTestPrefix() {
063        return TEST_PREFIX;
064    }
065
066    @Override
067    protected String getDefaultPrefix() {
068        return DEFAULT_PREFIX;
069    }
070
071    @Override
072    protected String getVersion() {
073        return LOG4J1_VERSION;
074    }
075}