When logging TranslatableMarkup, arguments aren't substituted into the message

Created on 2 August 2023, 11 months ago
Updated 1 June 2024, 29 days ago

Problem/Motivation

On Drupal 10, when a log message uses TranslatableMarkup or FormattableMarkup, JSONlog logs the original string containing placeholders, instead of substituting the arguments into the placeholders.

Steps to reproduce

When I run this:

drush eval '\Drupal::logger("test")->notice(t("test @someArgument", ["@someArgument" => "substituted text"]));'

JSONlog logs this:

{"@timestamp":"2023-08-01T23:59:37.744Z","@version":1,"message":"test @someArgument",…

Whereas I'd expect it to log this:

{"@timestamp":"2023-08-01T23:59:37.744Z","@version":1,"message":"test substituted text",…

Proposed resolution

Substitute the arguments into the string before writing it to the JSON log file.

Remaining tasks

Review patch.

User interface changes

n/a

API changes

n/a

Data model changes

This patch additionally logs the arguments as key-value pairs, which can be useful for structured log analysis.

πŸ› Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States smokris Athens, Ohio, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024