This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new e5894d9 LOG4J2-2973 Add tests for JSON-formatted configuration.
e5894d9 is described below
commit e5894d91eec8e80dddc549eab76eb71540f64e99
Author: Volkan Yazici <[email protected]>
AuthorDate: Wed Feb 3 11:24:02 2021 +0100
LOG4J2-2973 Add tests for JSON-formatted configuration.
---
.../JsonTemplateLayoutAdditionalFieldJsonTest.java | 36 +++++++++++++++++++
...onalFieldEnrichedJsonTemplateLayoutLogging.json | 42 ++++++++++++++++++++++
.../asciidoc/manual/json-template-layout.vm.adoc | 32 +++++++++++++++--
3 files changed, 107 insertions(+), 3 deletions(-)
diff --git
a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutAdditionalFieldJsonTest.java
b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutAdditionalFieldJsonTest.java
new file mode 100644
index 0000000..41fd023
--- /dev/null
+++
b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutAdditionalFieldJsonTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.layout.template.json;
+
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.jupiter.api.Test;
+
+@LoggerContextSource("additionalFieldEnrichedJsonTemplateLayoutLogging.json")
+class JsonTemplateLayoutAdditionalFieldJsonTest {
+
+ @Test
+ void test_additional_fields_are_resolved(
+ final LoggerContext loggerContext,
+ final @Named(value = "List") ListAppender appender) {
+ JsonTemplateLayoutAdditionalFieldTestHelpers
+ .assertAdditionalFields(loggerContext, appender);
+ }
+
+}
diff --git
a/log4j-layout-template-json/src/test/resources/additionalFieldEnrichedJsonTemplateLayoutLogging.json
b/log4j-layout-template-json/src/test/resources/additionalFieldEnrichedJsonTemplateLayoutLogging.json
new file mode 100644
index 0000000..493e3f3
--- /dev/null
+++
b/log4j-layout-template-json/src/test/resources/additionalFieldEnrichedJsonTemplateLayoutLogging.json
@@ -0,0 +1,42 @@
+{
+ "Configuration": {
+ "status": "OFF",
+ "appenders": {
+ "List": {
+ "name": "List",
+ "raw": "true",
+ "JsonTemplateLayout": {
+ "eventTemplateAdditionalField": [
+ {
+ "key": "stringField",
+ "value": "string"
+ },
+ {
+ "key": "numberField",
+ "value": "1",
+ "format": "JSON"
+ },
+ {
+ "key": "objectField",
+ "value": "{\"numberField\":1}",
+ "format": "JSON"
+ },
+ {
+ "key": "listField",
+ "value": "[1, \"two\"]",
+ "format": "JSON"
+ }
+ ]
+ }
+ }
+ },
+ "loggers": {
+ "root": {
+ "level": "trace",
+ "AppenderRef": {
+ "ref": "List"
+ }
+ }
+ }
+ }
+}
diff --git a/src/site/asciidoc/manual/json-template-layout.vm.adoc
b/src/site/asciidoc/manual/json-template-layout.vm.adoc
index 4575259..fa4c355 100644
--- a/src/site/asciidoc/manual/json-template-layout.vm.adoc
+++ b/src/site/asciidoc/manual/json-template-layout.vm.adoc
@@ -279,11 +279,11 @@ One can also provide JSON-formatted additional fields:
</JsonTemplateLayout>
----
-Additional event template fields can also be introduced using properties- and
-YAML-formatted configuration:
+Additional event template fields can very well be introduced using properties-,
+YAML-, and JSON-formatted configurations:
.Properties-formatted configuration with JSON-formatted additional fields
-[source, properties]
+[source,properties]
----
appender.console.layout.type = JsonTemplateLayout
appender.console.layout.eventTemplateUri = classpath:GelfLayout.json
@@ -317,6 +317,32 @@ JsonTemplateLayout:
format: "JSON"
----
+.JSON-formatted configuration with JSON-formatted additional fields
+[source,json]
+----
+{
+ "JsonTemplateLayout": {
+ "eventTemplateAdditionalField": [
+ {
+ "key": "marker",
+ "value": "{\"$resolver\": \"marker\", \"field\": \"name\"}",
+ "format": "JSON"
+ },
+ {
+ "key": "aNumber",
+ "value": "1",
+ "format": "JSON"
+ },
+ {
+ "key": "aList",
+ "value": "[1, 2, \"three\"]",
+ "format": "JSON"
+ }
+ ]
+ }
+}
+----
+
[#recycling-strategy]
=== Recycling strategy