Skip to content

Support json as a value of LOG_CONSOLE_FORMAT / LOG_FILE_FORMAT for JSON log lines - #4393

Merged
itzg merged 2 commits into
itzg:masterfrom
eliasehmann:log-json-format
Nov 14, 2026
Merged

itzg merged 2 commits into
itzg:masterfrom
eliasehmann:log-json-format

Conversation

@eliasehmann

Copy link
Copy Markdown
Contributor

Fixes #3870

When the image generates the log4j2 configuration (GENERATE_LOG4J2_CONFIG=true), LOG_CONSOLE_FORMAT, LOG_FILE_FORMAT and LOG_TERMINAL_FORMAT now accept json. The server then writes one JSON object per line using Elastic Common Schema field names, the same names as Log4j's EcsLayout.json template:

{"@timestamp":"2026-11-12T13:57:46.895Z","ecs.version":"1.2.0","log.level":"INFO","message":"No existing world data, creating new world","process.thread.name":"Worker-Main-6","log.logger":"net.minecraft.server.Main"}

error.stack_trace is added when an event carries an exception.

Why not JsonTemplateLayout

None of the server jars I checked include log4j-layout-template-json: vanilla 1.16.5, 1.18.2, 1.20.1 and 26.3, Paper 1.21.10, NeoForge 26.3 and the Fabric loader libraries. The image can't add it either, because the vanilla bundler and Paperclip load the server in a URLClassLoader whose parent is the platform class loader, so the JVM classpath isn't visible to Log4j. The JSON is therefore built with PatternLayout and %enc{...}{JSON}, which every Log4j bundled since Minecraft 1.18.1 (2.17+) supports. A top-level %ex{none} keeps Log4j 2.17/2.19 from appending a raw stack trace after the JSON.

Behavior

  • Setting a format variable to json changes only that output, so docker logs can be JSON while logs/latest.log stays text.
  • Minecraft older than 1.18.1: warning, then the default text format.
  • If the image isn't generating log4j2.xml, a warning says json is ignored.
  • Without json the generated log4j2.xml is unchanged.

Testing

  • Pattern checked against Log4j 2.17.0, 2.19.0, 2.24.1 and 2.26.0 with quotes, backslashes, newlines, control characters and a nested exception; every line parses with jq.
  • Ran the locally built image with vanilla 26.3, vanilla 1.18.2 and Paper 1.21.10 (console and file JSON): every Log4j line on stdout parses with jq. Vanilla 1.17.1 falls back to text with a warning. With the option off, the generated log4j2.xml is identical to the current image's.
  • Added setup-only test log4j-json.
  • Not run: Fabric, Forge and NeoForge servers (only their bundled libraries were checked).

Lines that don't come from Log4j (the [init] lines, the launcher's "Unpacking..." output, mc-server-runner) remain plain text, as noted in the docs.

…G_TERMINAL_FORMAT

Selecting json writes one JSON object per line with Elastic Common Schema
field names. The JSON is built with PatternLayout and %enc{...}{JSON} since
Minecraft server jars do not include log4j-layout-template-json and their
launchers load Log4j in an isolated class loader.

Requires Minecraft 1.18.1 or newer (Log4j 2.17); older versions keep the
default text format with a warning.

Fixes itzg#3870

@itzg itzg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be very nice

Comment thread scripts/start-finalExec-log4j Resolved
The pattern is stored unescaped and XML-escaped when it is read, instead
of carrying " entities and shell quote workarounds inline.
@itzg itzg added the status/ready to merge Indicates that the PR is ready to merge after all builds succeed. label Nov 14, 2026
@itzg
itzg merged commit 30b2642 into itzg:master Nov 14, 2026
8 checks passed
gabrielcosi pushed a commit to gabrielcosi/home-ops that referenced this pull request Nov 23, 2026
… βž” 2026.11.1) (#1900)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/itzg/minecraft-server](https://github.com/itzg/docker-minecraft-server) | patch | `2026.11.0-java25` β†’ `2026.11.1-java25` |

---

### Release Notes

<details>
<summary>itzg/docker-minecraft-server (ghcr.io/itzg/minecraft-server)</summary>

### [`v2026.11.1`](https://github.com/itzg/docker-minecraft-server/releases/tag/2026.11.1)

[Compare Source](itzg/docker-minecraft-server@2026.11.0...2026.11.1)

<!-- Release notes generated using configuration in .github/release.yml at 0699bd8497cb1e3c8e257fecd4320671194c6903 -->

#### What's Changed

##### Enhancements

- Support `json` as a value of `LOG_CONSOLE_FORMAT` / `LOG_FILE_FORMAT` for JSON log lines by [@&#8203;eliasehmann](https://github.com/eliasehmann) in [#&#8203;4393](itzg/docker-minecraft-server#4393)
- Exclude client-only Smart Particles and You Must Know This Notice for CurseForge packs by [@&#8203;Wroud](https://github.com/Wroud) in [#&#8203;4396](itzg/docker-minecraft-server#4396)
- Mitigate Java4Shell by disabling UseBASE64Intrinsics for Java 17 and newer versions by [@&#8203;itzg](https://github.com/itzg) in [#&#8203;4400](itzg/docker-minecraft-server#4400)
- Add HANGAR_PROJECTS to download plugins from Hangar by [@&#8203;caunt](https://github.com/caunt) in [#&#8203;4392](itzg/docker-minecraft-server#4392)
- Java4Shell is now fixed in base image by [@&#8203;itzg](https://github.com/itzg) in [#&#8203;4409](itzg/docker-minecraft-server#4409)

##### Documentation

- build(deps): bump the patches group in /docs with 2 updates by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;4402](itzg/docker-minecraft-server#4402)
- build(deps): bump pymdown-extensions from 12.3 to 13.1 in /docs by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;4403](itzg/docker-minecraft-server#4403)
- docs: add Minecraft Server Manager (MSM) to related projects by [@&#8203;anefzaoui](https://github.com/anefzaoui) in [#&#8203;4407](itzg/docker-minecraft-server#4407)

##### Other Changes

- Update dependency itzg/mc-image-helper to v1.76.2 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;4386](itzg/docker-minecraft-server#4386)
- build(deps): bump docker/login-action from 4.7.0 to 4.8.0 in the updates group by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;4387](itzg/docker-minecraft-server#4387)
- build(deps): combine docs dependency updates by [@&#8203;itzg](https://github.com/itzg) in [#&#8203;4390](itzg/docker-minecraft-server#4390)
- Update all non-major dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;4391](itzg/docker-minecraft-server#4391)
- Update all non-major dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;4395](itzg/docker-minecraft-server#4395)
- Update all non-major dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;4397](itzg/docker-minecraft-server#4397)
- Update dependency itzg/mc-image-helper to v1.78.1 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;4398](itzg/docker-minecraft-server#4398)
- Parse .mc-health.env instead of sourcing it by [@&#8203;lbellows](https://github.com/lbellows) in [#&#8203;4399](itzg/docker-minecraft-server#4399)
- Update dependency itzg/mc-image-helper to v1.78.2 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;4401](itzg/docker-minecraft-server#4401)
- Update all non-major dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;4410](itzg/docker-minecraft-server#4410)

#### New Contributors

- [@&#8203;eliasehmann](https://github.com/eliasehmann) made their first contribution in [#&#8203;4393](itzg/docker-minecraft-server#4393)
- [@&#8203;anefzaoui](https://github.com/anefzaoui) made their first contribution in [#&#8203;4407](itzg/docker-minecraft-server#4407)

**Full Changelog**: <itzg/docker-minecraft-server@2026.11.0...2026.11.1>

</details>

---

### Configuration

πŸ“… **Schedule**: (in timezone Europe/Berlin)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

πŸ”• **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Operator](https://github.com/mogenius/renovate-operator).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yNTcuNSIsInVwZGF0ZWRJblZlciI6IjQ0LjI1Ny41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.xcd.dev/gabrielcosi/home-ops/pulls/1900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement status/ready to merge Indicates that the PR is ready to merge after all builds succeed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add first-class JSON log output (Log4j2 JsonTemplateLayout) via env var

2 participants