1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.config.properties;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.util.Properties;
22
23 import org.apache.logging.log4j.core.config.ConfigurationException;
24 import org.apache.logging.log4j.core.config.ConfigurationFactory;
25 import org.apache.logging.log4j.core.config.ConfigurationSource;
26 import org.apache.logging.log4j.core.config.Order;
27 import org.apache.logging.log4j.core.config.plugins.Plugin;
28
29
30
31
32
33
34 @Plugin(name = "PropertiesConfigurationFactory", category = ConfigurationFactory.CATEGORY)
35 @Order(8)
36 public class PropertiesConfigurationFactory extends ConfigurationFactory {
37
38 @Override
39 protected String[] getSupportedTypes() {
40 return new String[] {".properties"};
41 }
42
43 @Override
44 public PropertiesConfiguration getConfiguration(final ConfigurationSource source) {
45 final InputStream configStream = source.getInputStream();
46 final Properties properties = new Properties();
47 try {
48 properties.load(configStream);
49 } catch (final IOException ioe) {
50 throw new ConfigurationException("Unable to load " + source.toString(), ioe);
51 }
52 return new PropertiesConfigurationBuilder().setConfigurationSource(source)
53 .setRootProperties(properties).build();
54 }
55 }