Problem/Motivation

See if PSR/log 3 compatibility is possible after the update to Symfony 6, and add forward to compatibility to core for its changes.

Follow-up issue of #3264918: Update symfony/console to Symfony 6

If we do this Drush will become uninstallable until the following things are fixed:
https://github.com/grasmash/expander/pull/17
https://github.com/consolidation/log/pull/27
https://github.com/consolidation/annotated-command/pull/266
https://github.com/consolidation/robo/pull/1109

Proposed resolution

Remaining tasks

User interface changes

None

API changes

Code that implements \Psr\Log\LoggerInterface will need to be updated. Typically code that uses the \Drupal\Core\Logger\RfcLoggerTrait will only need to change:

public function log($level, $message, array $context = []) {

to

public function log($level, string|\Stringable $message, array $context = []): void {

Data model changes

None

Release notes snippet

Psr/Log has been updated to version 3. All the methods that are on \Psr\Log\LoggerInterface have stricter typehints. Contrib and custom modules that provide logger implementations will need to be updated for Drupal 10.

Comments

Spokje created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new9.35 KB

Here's a go at this.

alexpott’s picture

Issue summary: View changes
catch’s picture

+++ b/core/modules/dblog/src/Logger/DbLog.php
@@ -52,7 +52,7 @@ public function __construct(Connection $connection, LogMessageParserInterface $p
    * {@inheritdoc}
    */
-  public function log($level, $message, array $context = []) {
+  public function log($level, string|\Stringable $message, array $context = []): void {
     // Remove backtrace and exception since they may contain an unserializable variable.

This is tricky - contrib modules will have to make the same change. I guess they could conditionally define the method depending on core version?

alexpott’s picture

@catch yeah it is tricky. This is why Symfony use their debug classloader and emit deprecations so they can warn people about stuff like this. In order to be both D9 and D10 compatible you'll have to do something like https://github.com/Chi-teck/drupal-code-generator/pull/83. If we do do this if I was a maintainer of a logging module I'd maintain separate D9 and D10 versions and add the psr/log dependency to my composer.json.

catch’s picture

We need to decide whether to do this or not for 10.x, and it's starting to get a bit late. If we do it, it'll be a breaking change for contrib logging modules, and they'll probably need 10.x-specific branches.

Looks like all the drush issues are fixed now.

If we don't, it'll probably be an 11.x blocker.

alexpott’s picture

Title: See if PSR/log 3 compatibility is possible after the update to Symfony 6 » Update to PSR/log v3
Issue summary: View changes
Issue tags: -Needs change record, -Needs release note

For me we should do this for Drupal 10. This is exactly the time when we should be updating the major versions of our dependencies. I think given the existence of \Drupal\Core\Logger\RfcLoggerTrait updates will be quite small.

alexpott’s picture

StatusFileSize
new6 KB
new9.35 KB

Re-rolled the patch...

@catch re:

and they'll probably need 10.x-specific branches.

I don't think this is true. I think if you only make the change to log method to add the return type hint it will still work. See the patch attached that only makes the code changes but not the update to the library.

catch’s picture

OK I was just following what you said in #5, hadn't actually thought it through.

If that's the case I think we should just go ahead here, we can find the contrib modules affected and open issues for them so they get a direct notification too.

The last submitted patch, 8: 3272447-no-update-8.patch, failed testing. View results

alexpott’s picture

Issue tags: -Needs framework manager review
StatusFileSize
new5.72 KB
new9.35 KB

Actually the most disruptive change has already occurred! 10.0.x is already on psr/log v2 and 9.x is on v1.

For what it is worth it is possible to have something that is compatible with v1 and v3... see attached noupdate2 patch...

Also we've already changed the major version for Drupal 10 - see #3266017: Update psr/log to v2

I think my reviews here resolve the needs framework manager tag.

alexpott’s picture

Issue summary: View changes
catch’s picture

New CR shows the minimal necessary change, and maintaining compatibility between Drupal 9 and Drupal 10, is just adding a void return type hint, so agreed the easiest thing to do will be to update, and as @alexpott points out we've already gone to psr/2.

No changes needed in 9.5.x so the 9.4.0 release isn't strictly relevant here too. Going to remove the 'needs release manager review' tag as well I think this is fine. edit: also confirmed with @xjm in slack that she's +1.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Let's just get this done now in D10, upstream packages are adding typehints all over the place, we need to be keeping up.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Needs a re-roll after #3275864: Update to Symfony 6.1.1 but ready to go otherwise.

spokje’s picture

StatusFileSize
new2.15 KB
new9.35 KB

Attempted a reroll

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Reroll looks good.

  • catch committed aac42cf on 10.0.x
    Issue #3272447 by alexpott, Spokje, catch, xjm: Update to PSR/log v3
    

catch credited xjm.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Crediting @xjm for the slack discussion.

Committed aac42cf and pushed to 10.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

Issue summary: View changes