Remove $context['user'] from LoggerChannel::log

Created on 17 July 2018, almost 6 years ago
Updated 14 September 2023, 9 months ago

Problem/Motivation

There is a line of code $context['user'] = $this->currentUser; inside of LoggerChannel::log() that was introduced as part of #1289536: Switch Watchdog to a PSR-3 logging framework β†’ .

When the log message includes some type of wildcard referencing {user*}, then \Drupal\Core\Logger\LogMessageParser::parseMessagePlaceholders() converts {users*} to @users* and then, because we have a context key 'user', it tries to put the AccountProxy object in there, which gives you this recoverable fatal error like: AccountProxy could not be converted to string

I tracked the code of the dblog and syslog and there is no use of the user object from the context array, just the uid. This makes sense since the username of a user can change, the only thing that does not vary is the user id.

Proposed resolution

  • Remove the non used line.
  • Create a change record that explicit indicates this lines was removed in case a contrib module was depending on this.

Please also credit to @penyaskito and @berdir in this issue.

πŸ› Bug report
Status

Fixed

Version

8.7 ⚰️

Component
SystemΒ  β†’

Last updated 1 day ago

No maintainer
Created by

πŸ‡¦πŸ‡·Argentina dagmar Argentina

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024