Skip to content

Add Log4j2 JsonTemplateLayout support for JSON log output#9209

Open
juanluisrp wants to merge 2 commits intomainfrom
log4j-json-template-layout
Open

Add Log4j2 JsonTemplateLayout support for JSON log output#9209
juanluisrp wants to merge 2 commits intomainfrom
log4j-json-template-layout

Conversation

@juanluisrp
Copy link
Contributor

@juanluisrp juanluisrp commented Mar 17, 2026

Summary

  • Add log4j-layout-template-json dependency to produce structured JSON logs via Log4j2's JsonTemplateLayout
  • Add new log4j2-json.xml configuration file that automatically appears as "JSON" in the Admin Settings log level dropdown (via existing LoggingApi regex discovery)
  • Each JSON log event includes @timestamp, level, loggerName, message, and exception fields, suitable for ELK stack ingestion
  • Harvester logs retain plain-text PatternLayout as they are consumed separately

Test plan

  • Build the web module and verify log4j-layout-template-json-2.17.2.jar appears in web/target/geonetwork/WEB-INF/lib/
  • Verify log4j2-json.xml appears in web/target/geonetwork/WEB-INF/classes/
  • Start GeoNetwork → Admin → Settings → verify "JSON" appears in the log level dropdown
  • Select "JSON" and confirm log output switches to structured JSON format

  Add the log4j-layout-template-json dependency and a new log4j2-json.xml
  configuration file that uses JsonTemplateLayout to produce structured
  JSON logs. Each log event includes @timestamp, level, loggerName,
  message, and exception fields suitable for ingestion by ELK stack or
  similar log aggregation tools.

  The file naming convention (log4j2-json.xml) makes the "JSON" option
  automatically available in the Admin Settings log level dropdown via the
  existing LoggingApi regex discovery mechanism.

  Harvester logs retain their existing PatternLayout as they are consumed
  separately.
Document Log4j2 configuration structure (appenders, pattern layout,
log rotation), harvester logging via routing appender, all available
logger modules, JSON logging sample output, custom log configuration
creation, REST API endpoints, and troubleshooting tips.

Also fix the log level preset list to match actual configuration
files (PROD, INDEX, DEV, TEST, JSON — there is no SEARCH preset).
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant