1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.appender.routing;
18
19 import org.apache.logging.log4j.Logger;
20 import org.apache.logging.log4j.core.config.plugins.Plugin;
21 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
22 import org.apache.logging.log4j.core.config.plugins.PluginElement;
23 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
24 import org.apache.logging.log4j.status.StatusLogger;
25
26
27
28
29 @Plugin(name = "Routes", category = "Core", printObject = true)
30 public final class Routes {
31
32 private static final Logger LOGGER = StatusLogger.getLogger();
33
34 private final String pattern;
35 private final Route[] routes;
36
37 private Routes(final String pattern, final Route... routes) {
38 this.pattern = pattern;
39 this.routes = routes;
40 }
41
42
43
44
45
46 public String getPattern() {
47 return pattern;
48 }
49
50
51
52
53
54 public Route[] getRoutes() {
55 return routes;
56 }
57
58 @Override
59 public String toString() {
60 final StringBuilder sb = new StringBuilder("{");
61 boolean first = true;
62 for (final Route route : routes) {
63 if (!first) {
64 sb.append(',');
65 }
66 first = false;
67 sb.append(route.toString());
68 }
69 sb.append('}');
70 return sb.toString();
71
72 }
73
74
75
76
77
78
79
80 @PluginFactory
81 public static Routes createRoutes(
82 @PluginAttribute("pattern") final String pattern,
83 @PluginElement("Routes") final Route... routes) {
84 if (pattern == null) {
85 LOGGER.error("A pattern is required");
86 return null;
87 }
88 if (routes == null || routes.length == 0) {
89 LOGGER.error("No routes configured");
90 return null;
91 }
92 return new Routes(pattern, routes);
93 }
94 }