This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/2.x by this push:
     new 613b27a6f5 Make `JsonTemplateLayout` implement `LocationAware` (#1692)
613b27a6f5 is described below

commit 613b27a6f520309de16b47ba59527ef76476282d
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Wed Aug 16 22:44:09 2023 +0200

    Make `JsonTemplateLayout` implement `LocationAware` (#1692)
---
 .../layout/template/json/JsonTemplateLayout.java   | 11 ++++++++-
 .../.2.x.x/1692_make_JTL_LocationAware.xml         | 28 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git 
a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java
 
b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java
index 1b05a59bb0..0311f0dce4 100644
--- 
a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java
+++ 
b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java
@@ -37,6 +37,7 @@ 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.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.impl.LocationAware;
 import org.apache.logging.log4j.core.layout.ByteBufferDestination;
 import org.apache.logging.log4j.core.layout.Encoder;
 import org.apache.logging.log4j.core.layout.TextEncoderHelper;
@@ -60,7 +61,7 @@ import org.apache.logging.log4j.util.Strings;
 @Plugin(name = "JsonTemplateLayout",
         category = Node.CATEGORY,
         elementType = Layout.ELEMENT_TYPE)
-public final class JsonTemplateLayout implements StringLayout {
+public final class JsonTemplateLayout implements StringLayout, LocationAware {
 
     private static final Map<String, String> CONTENT_FORMAT =
             Collections.singletonMap("version", "1");
@@ -69,6 +70,8 @@ public final class JsonTemplateLayout implements StringLayout 
{
 
     private final String contentType;
 
+    private final boolean locationInfoEnabled;
+
     private final TemplateResolver<LogEvent> eventResolver;
 
     private final String eventDelimiter;
@@ -98,6 +101,7 @@ public final class JsonTemplateLayout implements 
StringLayout {
     private JsonTemplateLayout(final Builder builder) {
         this.charset = builder.charset;
         this.contentType = "application/json; charset=" + charset;
+        this.locationInfoEnabled = builder.locationInfoEnabled;
         final String eventDelimiterSuffix = 
builder.isNullEventDelimiterEnabled() ? "\0" : "";
         this.eventDelimiter = builder.eventDelimiter + eventDelimiterSuffix;
         final Configuration configuration = builder.configuration;
@@ -328,6 +332,11 @@ public final class JsonTemplateLayout implements 
StringLayout {
         return charset;
     }
 
+    @Override
+    public boolean requiresLocation() {
+        return locationInfoEnabled;
+    }
+
     @Override
     public String getContentType() {
         return contentType;
diff --git a/src/changelog/.2.x.x/1692_make_JTL_LocationAware.xml 
b/src/changelog/.2.x.x/1692_make_JTL_LocationAware.xml
new file mode 100644
index 0000000000..0de933693e
--- /dev/null
+++ b/src/changelog/.2.x.x/1692_make_JTL_LocationAware.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="http://logging.apache.org/log4j/changelog";
+       xsi:schemaLocation="http://logging.apache.org/log4j/changelog 
https://logging.apache.org/log4j/changelog-0.1.0.xsd";
+       type="fixed">
+  <issue id="1692" 
link="https://github.com/apache/logging-log4j2/issues/1692"/>
+  <author name="Jalyn Xing" id="github:jalynxing"/>
+  <author id="github:vy"/>
+  <description format="asciidoc">
+    `JsonTemplateLayout` was missing to implement `LocationAware` and this was 
causing location not being passed to underlying appenders
+  </description>
+</entry>

Reply via email to