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