1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.config;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.apache.logging.log4j.core.config.plugins.Plugin;
23 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
24 import org.apache.logging.log4j.core.config.plugins.PluginElement;
25 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
26 import org.apache.logging.log4j.core.lookup.Interpolator;
27 import org.apache.logging.log4j.core.lookup.MapLookup;
28 import org.apache.logging.log4j.core.lookup.StrLookup;
29
30
31
32
33 @Plugin(name = "properties", category = Node.CATEGORY, printObject = true)
34 public final class PropertiesPlugin {
35
36 private PropertiesPlugin() {
37 }
38
39
40
41
42
43
44
45 @PluginFactory
46 public static StrLookup configureSubstitutor(@PluginElement("Properties") final Property[] properties,
47 @PluginConfiguration final Configuration config) {
48 if (properties == null) {
49 return new Interpolator(config.getProperties());
50 }
51 final Map<String, String> map = new HashMap<String, String>(config.getProperties());
52
53 for (final Property prop : properties) {
54 map.put(prop.getName(), prop.getValue());
55 }
56
57 return new Interpolator(new MapLookup(map), config.getPluginPackages());
58 }
59 }