1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.appender.db.nosql;
18
19 import org.apache.logging.log4j.core.Filter;
20 import org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender;
21 import org.apache.logging.log4j.core.config.plugins.Plugin;
22 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
23 import org.apache.logging.log4j.core.config.plugins.PluginElement;
24 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
25
26
27
28
29
30
31
32
33
34
35
36
37
38 @Plugin(name = "NoSql", category = "Core", elementType = "appender", printObject = true)
39 public final class NoSQLAppender extends AbstractDatabaseAppender<NoSQLDatabaseManager<?>> {
40 private final String description;
41
42 private NoSQLAppender(final String name, final Filter filter, final boolean handleException,
43 final NoSQLDatabaseManager<?> manager) {
44 super(name, filter, handleException, manager);
45 this.description = this.getName() + "{ manager=" + this.getManager() + " }";
46 }
47
48 @Override
49 public String toString() {
50 return this.description;
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64
65 @PluginFactory
66 public static NoSQLAppender createAppender(@PluginAttr("name") final String name,
67 @PluginAttr("suppressExceptions") final String suppressExceptions,
68 @PluginElement("filter") final Filter filter,
69 @PluginAttr("bufferSize") final String bufferSize,
70 @PluginElement("noSqlProvider") final NoSQLProvider<?> provider) {
71 if (provider == null) {
72 LOGGER.error("NoSQL provider not specified for appender [{}].", name);
73 return null;
74 }
75
76 int bufferSizeInt;
77 try {
78 bufferSizeInt = bufferSize == null || bufferSize.length() == 0 ? 0 : Integer.parseInt(bufferSize);
79 } catch (final NumberFormatException e) {
80 LOGGER.warn("Buffer size [" + bufferSize + "] not an integer, using no buffer.");
81 bufferSizeInt = 0;
82 }
83
84 final boolean handleExceptions = suppressExceptions == null || !Boolean.parseBoolean(suppressExceptions);
85
86 final String managerName = "noSqlManager{ description=" + name + ", bufferSize=" + bufferSizeInt
87 + ", provider=" + provider + " }";
88
89 final NoSQLDatabaseManager<?> manager = NoSQLDatabaseManager.getNoSQLDatabaseManager(
90 managerName, bufferSizeInt, provider
91 );
92 if (manager == null) {
93 return null;
94 }
95
96 return new NoSQLAppender(name, filter, handleExceptions, manager);
97 }
98 }