Problem/Motivation
If you have e.g. an exception when writing to a user table, then \Drupal\Core\Logger\LogMessageParser::parseMessagePlaceholders() converts {users_field_data} to @users_field_data 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:
Object of class Drupal\Core\Session\AccountProxy could not be converted to string
Proposed resolution
Only replace {something} with @something if we actually have something in $context?
Possibly also explicitly exclude keys that we do not want to get replaces, so even if you have {user}, that it will not try to replace it.
Comments
Comment #2
edurenye commentedComment #5
dagmarMoved to
dblog.modulefor future triage.Comment #6
berdirComment #7
dagmar@Berdir This seems legit, can you provide a way to replicate this issue so we can write a test to expose it? Thanks
Comment #8
berdirJust run this:
\Drupal::logger('foo')->warning('This is enough to reproduce it: {users_field_data}');
Then access /admin/reports/dblog. That "only" gives you a warning, but e.g. drush ps dies with an exception.
Comment #9
dagmarThanks @Berdir. So, the only way to get this fatal error if is a log message includes the
{users_field_data}in the message and not as a placeholder replacement (Which is what drupal usually do). I tried to trigger an exception as the IS says:And this allows me to use
drush ws. Still a valid issue. I'm just changing the priority.Comment #10
berdirYour example works because the error message itself is an argument, so it's not getting further replaced. Which is the default with watchdog_exception()
Fine with changing to normal, in our case we had it in combination with migrate exceptions that where logged with custom error handling I think.
Comment #11
michfuer commentedI'm seeing the same error when trying to log a message like
@user is getting added to the context. Looks like line 28 of LogMessageParser.php (on Drupal 8.2.7)
what about trying an exact match, something like
Comment #15
dagmarMarking as duplicate of #2986294: Remove $context['user'] from LoggerChannel::log @Berdir could you take a look to the patch provided there?