Github user jvz commented on a diff in the pull request:
https://github.com/apache/logging-log4j2/pull/74#discussion_r113045904
--- Diff:
log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/lucene/LuceneAppender.java
---
@@ -0,0 +1,301 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.nosql.appender.lucene;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.nio.file.Paths;
+import java.util.Calendar;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.appender.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.Node;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import
org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.util.Strings;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.LongField;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.search.NumericRangeQuery;
+import org.apache.lucene.store.FSDirectory;
+
+/**
+ * This Appender writes logging events to a lucene index library. It takes
a list of
+ * {@link IndexField} with which determines which fields are written to
the index library.
+ * <Lucene name="lucene" ignoreExceptions="true"
target="/target/lucene/index">
+ * <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level
%class{36} %L %M - %msg%xEx%n"/>
+ *
+ * <IndexField name="time" pattern="%d{UNIX_MILLIS}" type="LongField"/>
+ * <IndexField name="level" pattern="%-5level" />
+ * <IndexField name="content" pattern="%d{HH:mm:ss.SSS} %-5level
%class{36} %L %M - %msg%xEx%n"/>
+ * </Lucene>
+ */
+@Plugin(name = "Lucene", category = Node.CATEGORY, elementType =
Appender.ELEMENT_TYPE, printObject = true)
+public class LuceneAppender extends AbstractAppender {
+ /**
+ * index directory
+ */
+ private final String target;
+ /**
+ * Index expiration time (seconds)
+ */
+ private final Integer expiryTime;
+ /**
+ * IndexField array.
+ */
+ private final LuceneIndexField[] indexFields;
+ /**
+ * Periodically clear the index and submit the IndexWriter thread pool
+ */
+ private final ScheduledExecutorService scheduledExecutor =
Executors.newScheduledThreadPool(2);
+ /**
+ * IndexWriter corresponding to each index directory.
+ */
+ private static final ConcurrentHashMap<String, IndexWriter> writerMap =
new ConcurrentHashMap<String, IndexWriter>();
--- End diff --
I can't say that this is enforced everywhere, but the general pattern we
like to follow is that shared state for appenders are handled by a manager
class instead of static fields. Helps with certain deployment scenarios like
WARs, reconfigurations, and multiple appenders using the same config.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---