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 java.util.HashMap;
20 import java.util.Map;
21
22 import org.apache.logging.log4j.core.config.Configuration;
23 import org.apache.logging.log4j.core.config.Property;
24 import org.apache.logging.log4j.core.lookup.Interpolator;
25 import org.apache.logging.log4j.core.lookup.MapLookup;
26 import org.apache.logging.log4j.core.lookup.StrLookup;
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(config.getProperties());
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 }