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 */ 017package org.apache.log4j.config; 018 019import java.io.IOException; 020import java.io.InputStream; 021 022import org.apache.logging.log4j.core.LoggerContext; 023import org.apache.logging.log4j.core.config.Configuration; 024import org.apache.logging.log4j.core.config.ConfigurationException; 025import org.apache.logging.log4j.core.config.ConfigurationFactory; 026import org.apache.logging.log4j.core.config.ConfigurationSource; 027import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; 028import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; 029 030/** 031 * Experimental ConfigurationFactory for Log4j 1.2 properties configuration files. 032 */ 033// TODO 034// @Plugin(name = "Log4j1ConfigurationFactory", category = ConfigurationFactory.CATEGORY) 035// 036// Best Value? 037// @Order(50) 038public class Log4j1ConfigurationFactory extends ConfigurationFactory { 039 040 private static final String[] SUFFIXES = { ".properties" }; 041 042 @Override 043 public Configuration getConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) { 044 final ConfigurationBuilder<BuiltConfiguration> builder; 045 try (final InputStream configStream = source.getInputStream()) { 046 builder = new Log4j1ConfigurationParser().buildConfigurationBuilder(configStream); 047 } catch (final IOException e) { 048 throw new ConfigurationException("Unable to load " + source, e); 049 } 050 return builder.build(); 051 } 052 053 @Override 054 protected String[] getSupportedTypes() { 055 return SUFFIXES; 056 } 057 058}