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.xml; 019 020import org.apache.log4j.config.Log4j1Configuration; 021import org.apache.logging.log4j.core.LoggerContext; 022import org.apache.logging.log4j.core.config.Configuration; 023import org.apache.logging.log4j.core.config.ConfigurationFactory; 024import org.apache.logging.log4j.core.config.ConfigurationSource; 025import org.apache.logging.log4j.core.config.Order; 026import org.apache.logging.log4j.core.config.plugins.Plugin; 027import org.apache.logging.log4j.status.StatusLogger; 028import org.apache.logging.log4j.util.PropertiesUtil; 029 030/** 031 * Constructs a Configuration usable in Log4j 2 from a Log4j 1 configuration file. 032 */ 033@Plugin(name = "Log4j1XmlConfigurationFactory", category = ConfigurationFactory.CATEGORY) 034@Order(2) 035public class XmlConfigurationFactory extends ConfigurationFactory { 036 037 public static final String FILE_EXTENSION = ".xml"; 038 039 private static final org.apache.logging.log4j.Logger LOGGER = StatusLogger.getLogger(); 040 041 /** 042 * File name prefix for test configurations. 043 */ 044 protected static final String TEST_PREFIX = "log4j-test"; 045 046 /** 047 * File name prefix for standard configurations. 048 */ 049 protected static final String DEFAULT_PREFIX = "log4j"; 050 051 @Override 052 protected String[] getSupportedTypes() { 053 if (!PropertiesUtil.getProperties().getBooleanProperty(ConfigurationFactory.LOG4J1_EXPERIMENTAL, Boolean.FALSE)) { 054 return null; 055 } 056 return new String[] { FILE_EXTENSION }; 057 } 058 059 @Override 060 public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) { 061 int interval = PropertiesUtil.getProperties().getIntegerProperty(Log4j1Configuration.MONITOR_INTERVAL, 0); 062 return new XmlConfiguration(loggerContext, source, interval); 063 } 064 065 @Override 066 protected String getTestPrefix() { 067 return TEST_PREFIX; 068 } 069 070 @Override 071 protected String getDefaultPrefix() { 072 return DEFAULT_PREFIX; 073 } 074 075 @Override 076 protected String getVersion() { 077 return LOG4J1_VERSION; 078 } 079}