Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bookkeeper-benchmark/conf/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
<Configuration status="warn" monitorInterval="10">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m %X%n"/>
</Console>
<File name="TRACEFILE" fileName="bookkeeper_trace.log">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] - %m %X%n"/>
</File>
<RollingFile name="ROLLINGFILE" fileName="bookkeeper-benchmark.log" filePattern="bookkeeper-benchmark.log%d{.yyyy-MM-dd}">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m %X%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true"/>
</Policies>
Expand Down
2 changes: 1 addition & 1 deletion bookkeeper-server/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<Configuration status="warn" monitorInterval="10">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m %X%n"/>
</Console>
</Appenders>
<Loggers>
Expand Down
2 changes: 1 addition & 1 deletion conf/log4j2.cli.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PatternLayout pattern="%m%n"/>
</Console>
<RollingFile name="ROLLINGFILE" fileName="${sys:bookkeeper.cli.log.dir}/${sys:bookkeeper.cli.log.file}" filePattern="${sys:bookkeeper.cli.log.dir}/${sys:bookkeeper.cli.log.file}%d{.yyyy-MM-dd}">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m %X%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true"/>
</Policies>
Expand Down
86 changes: 86 additions & 0 deletions conf/log4j2.otel-json.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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.

-->
<!--
Example log4j2 configuration that emits each log event as a single JSON
object aligned with the OpenTelemetry log data model
(https://opentelemetry.io/docs/specs/otel/logs/data-model/).

Required runtime dependency (NOT included by default in BookKeeper):
org.apache.logging.log4j:log4j-layout-template-json:${log4j.version}

Add it to the classpath alongside log4j-core to enable JsonTemplateLayout.

The event template lives in conf/otel-log-template.json. Customize it
there (e.g. add resource attributes, drop fields, rename keys) without
touching this file.

Top-level fields follow the OTel data-model field naming (PascalCase):
* "Timestamp" = event time, ISO-8601 UTC.
* "SeverityText" = log4j level name ("INFO", "WARN", ...).
* "Body" = the log message string.
* "TraceId" / "SpanId" / "TraceFlags"
= MDC keys conventionally set by the
OpenTelemetry log appender bridge; omitted
when absent.
* "Attributes" = OTel-semantic-conventions attributes for the
event:
- thread.name / thread.id
- code.namespace (= the logger name)
- exception.type / .message / .stacktrace
Plus the full Log4j2 ContextData map (every
slog ".attr(...)" entry and any SLF4J MDC
key) merged in via the "mdc" resolver with
flatten=true.
-->
<Configuration status="warn" monitorInterval="10">
<Properties>
<Property name="bookkeeper.log.dir">.</Property>
<Property name="bookkeeper.log.file">bookkeeper-server.json.log</Property>
<Property name="bookkeeper.log.root.level">INFO</Property>
<Property name="bookkeeper.log.root.appender">CONSOLE</Property>
<Property name="otel.template">file:${sys:bookkeeper.conf.dir:-conf}/otel-log-template.json</Property>
</Properties>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<JsonTemplateLayout eventTemplateUri="${otel.template}"/>
</Console>
<RollingFile name="ROLLINGFILE"
fileName="${sys:bookkeeper.log.dir}/${sys:bookkeeper.log.file}"
filePattern="${sys:bookkeeper.log.dir}/${sys:bookkeeper.log.file}%d{.yyyy-MM-dd}">
<!--
Each line is an independent JSON object (ndjson), directly
consumable by log shippers (FluentBit, Vector, Fluentd,
Promtail, otel-collector, ...).
-->
<JsonTemplateLayout eventTemplateUri="${otel.template}"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="${sys:bookkeeper.log.root.level}">
<AppenderRef ref="${sys:bookkeeper.log.root.appender}"/>
</Root>
</Loggers>
</Configuration>
2 changes: 1 addition & 1 deletion conf/log4j2.shell.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PatternLayout pattern="%d{ABSOLUTE} %-5p %m%n"/>
</Console>
<RollingFile name="ROLLINGFILE" fileName="${sys:bookkeeper.shell.log.dir}/${sys:bookkeeper.shell.log.file}" filePattern="${sys:bookkeeper.shell.log.dir}/${sys:bookkeeper.shell.log.file}%d{.yyyy-MM-dd}">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m %X%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true"/>
</Policies>
Expand Down
29 changes: 10 additions & 19 deletions conf/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,21 @@
<Property name="bookkeeper.log.root.appender">CONSOLE</Property>
</Properties>
<Appenders>
<!--
The "%X" pattern element renders the structured attributes attached
to each log event (slog ".attr(...)" calls and any java.util.MDC /
Log4j2 ThreadContext entries). It is rendered as "{key=value, ...}".
Drop or replace it with named keys (e.g. %X{ledgerId}) for a more
specific format.
-->
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n"/>
</Console>
<Console name="CONSOLEMDC" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] %X - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m %X%n"/>
</Console>
<File name="TRACEFILE" fileName="${sys:bookkeeper.log.dir}/bookkeeper-trace.log">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] - %m%n"/>
</File>
<File name="TRACEFILEMDC" fileName="${sys:bookkeeper.log.dir}/bookkeeper-trace.log">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] %X - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] - %m %X%n"/>
</File>
<RollingFile name="ROLLINGFILE" fileName="${sys:bookkeeper.log.dir}/${sys:bookkeeper.log.file}" filePattern="${sys:bookkeeper.log.dir}/${sys:bookkeeper.log.file}%d{.yyyy-MM-dd}">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>
<RollingFile name="ROLLINGFILEMDC" fileName="${sys:bookkeeper.log.dir}/${sys:bookkeeper.log.file}" filePattern="${sys:bookkeeper.log.dir}/${sys:bookkeeper.log.file}%d{.yyyy-MM-dd}">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L] %X - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m %X%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true"/>
</Policies>
Expand All @@ -58,8 +52,5 @@
<Root level="${sys:bookkeeper.log.root.level}">
<AppenderRef ref="${sys:bookkeeper.log.root.appender}"/>
</Root>
<Logger name="org.apache.bookkeeper.bookie.storage.directentrylogger" level="INFO">
<AppenderRef ref="${sys:bookkeeper.log.root.appender}MDC"/>
</Logger>
</Loggers>
</Configuration>
63 changes: 63 additions & 0 deletions conf/otel-log-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"Timestamp": {
"$resolver": "timestamp",
"pattern": {
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"timeZone": "UTC"
}
},
"SeverityText": {
"$resolver": "level",
"field": "name"
},
"Body": {
"$resolver": "message",
"stringified": true
},
"TraceId": {
"$resolver": "mdc",
"key": "trace_id"
},
"SpanId": {
"$resolver": "mdc",
"key": "span_id"
},
"TraceFlags": {
"$resolver": "mdc",
"key": "trace_flags"
},
"Attributes": {
"thread.name": {
"$resolver": "thread",
"field": "name"
},
"thread.id": {
"$resolver": "thread",
"field": "id"
},
"code.namespace": {
"$resolver": "logger",
"field": "name"
},
"exception.type": {
"$resolver": "exception",
"field": "className"
},
"exception.message": {
"$resolver": "exception",
"field": "message"
},
"exception.stacktrace": {
"$resolver": "exception",
"field": "stackTrace",
"stackTrace": {
"stringified": true
}
},
"mdc": {
"$resolver": "mdc",
"flatten": true,
"stringified": true
}
}
}
6 changes: 3 additions & 3 deletions stream/conf/log4j2.cli.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
</Properties>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m %X%n"/>
</Console>
<File name="TRACEFILE" fileName="${sys:streamstorage.log.dir}/streamstorage-trace.log">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] - %m %X%n"/>
</File>
<RollingFile name="ROLLINGFILE" fileName="${sys:streamstorage.log.dir}/${sys:streamstorage.log.file}" filePattern="${sys:streamstorage.log.dir}/${sys:streamstorage.log.file}%d{.yyyy-MM-dd}">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m %X%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true"/>
</Policies>
Expand Down
6 changes: 3 additions & 3 deletions stream/conf/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
</Properties>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m %X%n"/>
</Console>
<File name="TRACEFILE" fileName="${sys:streamstorage.log.dir}/streamstorage-trace.log">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L][%ndc] - %m %X%n"/>
</File>
<RollingFile name="ROLLINGFILE" fileName="${sys:streamstorage.log.dir}/${sys:streamstorage.log.file}" filePattern="${sys:streamstorage.log.dir}/${sys:streamstorage.log.file}%d{.yyyy-MM-dd}">
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n"/>
<PatternLayout pattern="%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m %X%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true"/>
</Policies>
Expand Down
Loading