[
https://issues.apache.org/jira/browse/KARAF-5792?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16603922#comment-16603922
]
ASF GitHub Bot commented on KARAF-5792:
---------------------------------------
jbonofre closed pull request #39: KARAF-5792 Support add, rename, remove to the
custom fields of Decant…
URL: https://github.com/apache/karaf-decanter/pull/39
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/collector/log/src/main/cfg/org.apache.karaf.decanter.collector.log.cfg
b/collector/log/src/main/cfg/org.apache.karaf.decanter.collector.log.cfg
index c3c11ec..b90ca0f 100644
--- a/collector/log/src/main/cfg/org.apache.karaf.decanter.collector.log.cfg
+++ b/collector/log/src/main/cfg/org.apache.karaf.decanter.collector.log.cfg
@@ -4,4 +4,13 @@
# logger categories that the log collector should ignore
# By default, we ignored all messages coming from Decanter Appenders
-ignored.categories=org.apache.karaf.decanter.appender.*
\ No newline at end of file
+ignored.categories=org.apache.karaf.decanter.appender.*
+
+# custom fields
+#fields.add.eventType=LOGEvent
+#fields.add.eventUUID=UUID
+#fields.add.serverTimestamp=TIMESTAMP
+#fields.rename.MDC=customInfo
+#fields.rename.level=severity
+#fields.rename.renderedMessage=logMessage
+#fields.remove.timestamp=true
diff --git
a/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
b/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
index 262bcd5..e1bb0c3 100644
---
a/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
+++
b/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
@@ -17,10 +17,13 @@
package org.apache.karaf.decanter.collector.log;
import java.net.InetAddress;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -54,10 +57,15 @@
private static final String MDC_IN_LOG_APPENDER = "inLogAppender";
private final static Logger LOGGER =
LoggerFactory.getLogger(LogAppender.class);
private final static Pattern PATTERN = Pattern.compile("[^A-Za-z0-9]");
+ private final static String FIELDS_ADD = "fields.add.";
+ private final static String FIELDS_RENAME = "fields.rename.";
+ private final static String FIELDS_REMOVE = "fields.remove.";
private Dictionary<String, Object> properties;
protected String[] ignoredCategories;
+ private SimpleDateFormat tsFormat;
+
@SuppressWarnings("unchecked")
@Activate
public void activate(ComponentContext context) {
@@ -65,6 +73,8 @@ public void activate(ComponentContext context) {
if (this.properties.get("ignored.categories") != null) {
ignoredCategories =
((String)this.properties.get("ignored.categories")).split(",");
}
+
+ tsFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
}
public void doAppend(PaxLoggingEvent event) {
@@ -100,13 +110,6 @@ private void appendInternal(PaxLoggingEvent event) throws
Exception {
data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
data.put("hostName", InetAddress.getLocalHost().getHostName());
- // custom fields
- Enumeration<String> keys = properties.keys();
- while (keys.hasMoreElements()) {
- String key = keys.nextElement();
- data.put(key, properties.get(key));
- }
-
data.put("timestamp", event.getTimeStamp());
data.put("loggerClass", event.getFQNOfLoggerClass());
data.put("loggerName", event.getLoggerName());
@@ -121,6 +124,35 @@ private void appendInternal(PaxLoggingEvent event) throws
Exception {
data.put("throwable", join(throwableAr));
}
+ // custom fields
+ Enumeration<String> keys = properties.keys();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+ if (key.startsWith(FIELDS_ADD)) {
+ if ("UUID".equals(properties.get(key).toString().trim())) {
+ String uuid = UUID.randomUUID().toString();
+ data.put(key.substring(FIELDS_ADD.length()), uuid);
+ } else if
("TIMESTAMP".equals(properties.get(key).toString().trim())) {
+ Date date = new Date();
+ data.put(key.substring(FIELDS_ADD.length()),
tsFormat.format(date));
+ } else {
+ data.put(key.substring(FIELDS_ADD.length()),
properties.get(key));
+ }
+ } else if (key.startsWith(FIELDS_RENAME)) {
+ if (data.containsKey(key.substring(FIELDS_RENAME.length()))) {
+ Object value =
data.get(key.substring(FIELDS_RENAME.length()));
+ data.remove(key.substring(FIELDS_RENAME.length()));
+ data.put(properties.get(key).toString().trim(), value);
+ }
+ } else if (key.startsWith(FIELDS_REMOVE)) {
+ if (data.containsKey(key.substring(FIELDS_REMOVE.length()))) {
+ data.remove(key.substring(FIELDS_REMOVE.length()));
+ }
+ } else {
+ data.put(key, properties.get(key));
+ }
+ }
+
String loggerName = event.getLoggerName();
if (loggerName == null || loggerName.isEmpty()) {
loggerName = "default";
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Support add, rename, remove to the custom fields of Decanter log collector
> --------------------------------------------------------------------------
>
> Key: KARAF-5792
> URL: https://issues.apache.org/jira/browse/KARAF-5792
> Project: Karaf
> Issue Type: Improvement
> Components: decanter
> Affects Versions: decanter-2.0.0
> Reporter: Xilai Dai
> Assignee: Jean-Baptiste Onofré
> Priority: Major
> Fix For: decanter-2.1.0
>
>
> Now user can only "add" some custom fields with constant value in the
> org.apache.karaf.decanter.collector.log.cfg.
> {code}
> key1=value1
> key2=value2
> {code}
> But there is no chance to "rename" or "remove" some of the generated fields
> from the log collector, or add dynamic value e.g. UUID, Timestamp to the
> field.
> It would be benifit for user if the custom fields impl get improved in the
> log collector of Decanter. Configuration like this:
> {code}
> # custom fields
> fields.add.eventType=LOGEvent
> fields.add.eventUUID=UUID
> fields.add.serverTimestamp=TIMESTAMP
> fields.rename.MDC=customInfo
> fields.rename.level=severity
> fields.rename.renderedMessage=logMessage
> fields.remove.timestamp=true
> {code}
> Then it provides ability to "transformer" the json data on collector level,
> which will reduce the overhead user has to "transformer" the data later
> (using Filebeat or custom transformer bundle)
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)