Skip to content

Commit 85a9fc8

Browse files
[FLINK-36997] Add Log4j JSONTemplateLayout to flink-dist (apache#25888)
1 parent fe1b777 commit 85a9fc8

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

docs/content.zh/docs/deployment/advanced/logging.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,18 @@ Flink adds the following fields to [MDC](https://www.slf4j.org/api/org/slf4j/MDC
5050

5151
This is most useful in environments with structured logging and allows you to quickly filter the relevant logs.
5252

53-
The MDC is propagated by slf4j to the logging backend which usually adds it to the log records automatically (e.g. in [log4j json layout](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html)).
53+
The MDC is propagated by slf4j to the logging backend which usually adds it to the log records automatically (e.g. in [log4j2 json layout](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html#event-template-resolver-mdc).
54+
55+
#### Log4j 2 JsonTemplateLayout
56+
57+
> JsonTemplateLayout is a customizable, efficient, and garbage-free JSON generating layout. It encodes LogEvents according to the structure described by the JSON template provided.
58+
59+
The required jar `log4j-layout-template-json` is bundled in the flink-dist for convenience.
60+
61+
For example templates, see the [Event Templates](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html#event-templates).
62+
63+
#### Log4j 2 PatternLayout
64+
5465
Alternatively, it can be configured explicitly - [log4j pattern layout](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html) might look like this:
5566

5667
`[%-32X{flink-job-id}] %c{0} %m%n`.

docs/content/docs/deployment/advanced/logging.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@ Flink adds the following fields to [MDC](https://www.slf4j.org/api/org/slf4j/MDC
4848

4949
This is most useful in environments with structured logging and allows you to quickly filter the relevant logs.
5050

51-
The MDC is propagated by slf4j to the logging backend which usually adds it to the log records automatically (e.g. in [log4j json layout](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html)).
51+
The MDC is propagated by slf4j to the logging backend which usually adds it to the log records automatically (e.g. in [log4j2 json layout](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html#event-template-resolver-mdc).
52+
53+
#### Log4j 2 JsonTemplateLayout
54+
55+
> JsonTemplateLayout is a customizable, efficient, and garbage-free JSON generating layout. It encodes LogEvents according to the structure described by the JSON template provided.
56+
57+
The required jar `log4j-layout-template-json` is bundled in the flink-dist for convenience.
58+
59+
For example templates, see the [Event Templates](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html#event-templates).
60+
61+
#### Log4j 2 PatternLayout
62+
5263
Alternatively, it can be configured explicitly - [log4j pattern layout](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html) might look like this:
5364

5465
`[%-32X{flink-job-id}] %c{0} %m%n`.

flink-dist/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ under the License.
190190
<scope>compile</scope>
191191
</dependency>
192192

193+
<dependency>
194+
<groupId>org.apache.logging.log4j</groupId>
195+
<artifactId>log4j-layout-template-json</artifactId>
196+
<scope>compile</scope>
197+
</dependency>
198+
193199
<!-- Table dependencies -->
194200

195201
<dependency>

flink-dist/src/main/assemblies/bin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ under the License.
4242
<include>org.apache.logging.log4j:log4j-core</include>
4343
<include>org.apache.logging.log4j:log4j-slf4j-impl</include>
4444
<include>org.apache.logging.log4j:log4j-1.2-api</include>
45+
<include>org.apache.logging.log4j:log4j-layout-template-json</include>
4546
</includes>
4647
</dependencySet>
4748
</dependencySets>

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ under the License.
523523
<version>${log4j.version}</version>
524524
</dependency>
525525

526+
<dependency>
527+
<groupId>org.apache.logging.log4j</groupId>
528+
<artifactId>log4j-layout-template-json</artifactId>
529+
<version>${log4j.version}</version>
530+
</dependency>
531+
526532
<dependency>
527533
<!-- API bridge between log4j 1 and 2 -->
528534
<groupId>org.apache.logging.log4j</groupId>

0 commit comments

Comments
 (0)