|
30 | 30 | import org.apache.logging.log4j.core.Layout;
|
31 | 31 | import org.apache.logging.log4j.core.LogEvent;
|
32 | 32 | import org.apache.logging.log4j.core.appender.AbstractAppender;
|
| 33 | +import org.apache.logging.log4j.core.config.Property; |
33 | 34 | import org.apache.logging.log4j.core.config.plugins.Plugin;
|
34 |
| -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; |
35 |
| -import org.apache.logging.log4j.core.config.plugins.PluginElement; |
36 |
| -import org.apache.logging.log4j.core.config.plugins.PluginFactory; |
37 |
| -import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; |
38 |
| -import org.apache.logging.log4j.core.layout.PatternLayout; |
| 35 | +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; |
39 | 36 | import org.apache.logging.log4j.util.PropertiesUtil;
|
40 | 37 | import org.checkerframework.checker.nullness.qual.Nullable;
|
41 | 38 | import org.jline.reader.LineReader;
|
|
90 | 87 | @Plugin(name = TerminalConsoleAppender.PLUGIN_NAME, category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true)
|
91 | 88 | public final class TerminalConsoleAppender extends AbstractAppender {
|
92 | 89 |
|
| 90 | + /** |
| 91 | + * The name of the appender in the configuration. |
| 92 | + */ |
93 | 93 | public static final String PLUGIN_NAME = "TerminalConsole";
|
94 | 94 |
|
95 | 95 | /**
|
@@ -201,9 +201,11 @@ public static boolean isAnsiSupported() {
|
201 | 201 | * @param ignoreExceptions If {@code true} exceptions encountered when
|
202 | 202 | * appending events are logged, otherwise they are propagated to the
|
203 | 203 | * caller
|
| 204 | + * @param properties Optional properties |
204 | 205 | */
|
205 |
| - protected TerminalConsoleAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions) { |
206 |
| - super(name, filter, layout, ignoreExceptions); |
| 206 | + protected TerminalConsoleAppender(String name, Filter filter, Layout<? extends Serializable> layout, |
| 207 | + boolean ignoreExceptions, Property[] properties) { |
| 208 | + super(name, filter, layout, ignoreExceptions, properties); |
207 | 209 | if (!initialized)
|
208 | 210 | initializeTerminal();
|
209 | 211 | }
|
@@ -291,28 +293,29 @@ public synchronized static void close() throws IOException {
|
291 | 293 | }
|
292 | 294 |
|
293 | 295 | /**
|
294 |
| - * Creates a new {@link TerminalConsoleAppender}. |
| 296 | + * Creates a new {@link Builder} for {@link TerminalConsoleAppender}. |
295 | 297 | *
|
296 |
| - * @param name The name of the appender |
297 |
| - * @param filter The filter, can be {@code null} |
298 |
| - * @param layout The layout, can be {@code null} |
299 |
| - * @param ignoreExceptions If {@code true} exceptions encountered when |
300 |
| - * appending events are logged, otherwise they are propagated to the |
301 |
| - * caller |
302 |
| - * @return The new appender |
| 298 | + * @param <B> The type to build |
| 299 | + * @return The new builder |
303 | 300 | */
|
304 |
| - @PluginFactory |
305 |
| - public static TerminalConsoleAppender createAppender( |
306 |
| - @Required(message = "No name provided for TerminalConsoleAppender") @PluginAttribute("name") String name, |
307 |
| - @PluginElement("Filter") Filter filter, |
308 |
| - @PluginElement("Layout") @Nullable Layout<? extends Serializable> layout, |
309 |
| - @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) boolean ignoreExceptions) { |
310 |
| - |
311 |
| - if (layout == null) { |
312 |
| - layout = PatternLayout.createDefaultLayout(); |
313 |
| - } |
| 301 | + @PluginBuilderFactory |
| 302 | + public static <B extends Builder<B>> B newBuilder() { |
| 303 | + return new Builder<B>().asBuilder(); |
| 304 | + } |
314 | 305 |
|
315 |
| - return new TerminalConsoleAppender(name, filter, layout, ignoreExceptions); |
| 306 | + /** |
| 307 | + * Builds {@link TerminalConsoleAppender} instances. |
| 308 | + * |
| 309 | + * @param <B> The type to build |
| 310 | + */ |
| 311 | + public static class Builder<B extends Builder<B>> extends AbstractAppender.Builder<B> |
| 312 | + implements org.apache.logging.log4j.core.util.Builder<TerminalConsoleAppender> { |
| 313 | + |
| 314 | + @Override |
| 315 | + public TerminalConsoleAppender build() { |
| 316 | + return new TerminalConsoleAppender(getName(), getFilter(), getOrCreateLayout(), |
| 317 | + isIgnoreExceptions(), getPropertyArray()); |
| 318 | + } |
316 | 319 | }
|
317 | 320 |
|
318 | 321 | private static @Nullable Boolean getOptionalBooleanProperty(String name) {
|
|
0 commit comments