Logger property of EntityResource should be psr/log compatible

Created on 24 June 2024, 5 months ago
Updated 30 June 2024, 5 months ago

Problem/Motivation

When trying to install this module while using monolog, I get the following error:

TypeError: Cannot assign Psr\Log\NullLogger to property Drupal\jsonapi_defaults\Controller\EntityResource::$logger of type Drupal\Core\Logger\LoggerChannelInterface in /var/www/html/web/modules/contrib/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php on line 104 #0 [internal function]: Drupal\jsonapi_defaults\Controller\EntityResource->__construct(Object(Drupal\Core\Entity\EntityTypeManager), Object(Drupal\Core\Entity\EntityFieldManager), Object(Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository), Object(Drupal\Core\Render\Renderer), Object(Drupal\Core\Entity\EntityRepository), Object(Drupal\jsonapi\IncludeResolver), Object(Drupal\jsonapi\Access\EntityAccessChecker), Object(Drupal\jsonapi\Context\FieldResolver), Object(Drupal\jsonapi\Serializer\Serializer), Object(Drupal\Component\Datetime\Time), Object(Drupal\Core\Session\AccountProxy), Object(Drupal\jsonapi_defaults\JsonapiDefaults), Object(Drupal\monolog\Logger\MonologLoggerChannelFactory))
#1 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1140): ReflectionClass->newInstanceArgs(Array)
#2 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(586): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), Array, true, 'jsonapi.entity_...')
#3 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(531): Symfony\Component\DependencyInjection\ContainerBuilder->doGet('jsonapi.entity_...', 1)
#4 /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php(33): Symfony\Component\DependencyInjection\ContainerBuilder->get('jsonapi.entity_...')
#5 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityResolverManager.php(106): Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition('jsonapi.entity_...')
#6 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityResolverManager.php(219): Drupal\Core\Entity\EntityResolverManager->getControllerClass(Array)
#7 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EntityRouteAlterSubscriber.php(48): Drupal\Core\Entity\EntityResolverManager->setRouteOptions(Object(Symfony\Component\Routing\Route))
#8 [internal function]: Drupal\Core\EventSubscriber\EntityRouteAlterSubscriber->onRoutingRouteAlterSetType(Object(Drupal\Core\Routing\RouteBuildEvent), 'routing.route_a...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#9 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\Core\Routing\RouteBuildEvent), 'routing.route_a...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#10 /var/www/html/web/core/lib/Drupal/Core/Routing/RouteBuilder.php(189): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\Core\Routing\RouteBuildEvent), 'routing.route_a...')
#11 /var/www/html/web/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php(83): Drupal\Core\Routing\RouteBuilder->rebuild()
#12 /var/www/html/web/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php(67): Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild()
#13 /var/www/html/web/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php(83): Drupal\Core\Routing\RouteProviderLazyBuilder->getRouteProvider()
#14 /var/www/html/web/core/lib/Drupal/Core/Installer/InstallerRouteProviderLazyBuilder.php(23): Drupal\Core\Routing\RouteProviderLazyBuilder->getRouteByName('entity.entity_v...')
#15 /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php(443): Drupal\Core\Installer\InstallerRouteProviderLazyBuilder->getRouteByName('entity.entity_v...')
#16 /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php(276): Drupal\Core\Routing\UrlGenerator->getRoute('entity.entity_v...')
#17 /var/www/html/web/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php(108): Drupal\Core\Routing\UrlGenerator->generateFromRoute('entity.entity_v...', Array, Array, true)
#18 /var/www/html/web/core/lib/Drupal/Core/Url.php(765): Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute('entity.entity_v...', Array, Array, true)
#19 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(306): Drupal\Core\Url->toString(true)
#20 [internal function]: Drupal\Core\Entity\EntityBase->Drupal\Core\Entity\{closure}('delete-form')
#21 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(315): array_filter(Array, Object(Closure))
#22 /var/www/html/web/core/modules/menu_link_content/menu_link_content.module(105): Drupal\Core\Entity\EntityBase->uriRelationships()
#23 [internal function]: menu_link_content_entity_predelete(Object(Drupal\Core\Entity\Entity\EntityViewMode), 'entity_view_mod...')
#24 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(417): call_user_func_array(Object(Closure), Array)
#25 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(396): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object(Closure), 'menu_link_conte...')
#26 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(424): Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_predelet...', Object(Closure))
#27 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(343): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_predelet...', Array)
#28 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(452): Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('predelete', Object(Drupal\Core\Entity\Entity\EntityViewMode))
#29 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(362): Drupal\Core\Entity\EntityStorageBase->delete(Array)
#30 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(384): Drupal\Core\Entity\EntityBase->delete()
#31 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(1068): Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete('core.entity_vie...', Object(Drupal\Core\Config\Config), Object(Drupal\Core\Config\Config))
#32 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(851): Drupal\Core\Config\ConfigImporter->importInvokeOwner('', 'delete', 'core.entity_vie...')
#33 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(672): Drupal\Core\Config\ConfigImporter->processConfiguration('', 'delete', 'core.entity_vie...')
#34 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(570): Drupal\Core\Config\ConfigImporter->processConfigurations(Array)
#35 /var/www/html/web/core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php(31): Drupal\Core\Config\ConfigImporter->doSyncStep('processConfigur...', Array)
#36 /var/www/html/web/core/includes/batch.inc(296): Drupal\Core\Config\Importer\ConfigImporterBatch::process(Object(Drupal\Core\Config\ConfigImporter), 'processConfigur...', Array)
#37 /var/www/html/web/core/includes/form.inc(977): _batch_process()
#38 /var/www/html/web/core/includes/install.core.inc(654): batch_process(Object(Drupal\Core\Url), Object(Drupal\Core\Url))
#39 /var/www/html/web/core/includes/install.core.inc(572): install_run_task(Array, Array)
#40 /var/www/html/web/core/includes/install.core.inc(122): install_run_tasks(Array, Array)
#41 /var/www/html/vendor/drush/drush/includes/drush.inc(69): install_drupal(Object(Composer\Autoload\ClassLoader), Array, Array)
#42 /var/www/html/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array('install_drupal', Array)
#43 /var/www/html/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php(167): drush_op('install_drupal', Object(Composer\Autoload\ClassLoader), Array, Array)
#44 [internal function]: Drush\Commands\core\SiteInstallCommands->install('minimal', Array)
#45 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
#46 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#47 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#48 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#49 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#50 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#51 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#52 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#53 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#54 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#55 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#56 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#57 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')
#58 {main}
TypeError: Cannot assign Psr\Log\NullLogger to property Drupal\jsonapi_defaults\Controller\EntityResource::$logger of type Drupal\Core\Logger\LoggerChannelInterface in Drupal\jsonapi_defaults\Controller\EntityResource->__construct() (line 104 of /var/www/html/web/modules/contrib/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php).

For some reason it only started to happen after upgrading to Drupal 10.3. However, the point still stands. I could use a null logger while developing locally if I wanted :)

Steps to reproduce

Use monolog. Install the module. Probably clear the cache?

Proposed resolution

Use the logger annotations from psr/log instead. This is consistently done in core as well.

Remaining tasks

- review
- commit

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡³πŸ‡΄Norway eiriksm Norway

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

Merge Requests

Comments & Activities

  • Issue created by @eiriksm
  • Merge request !54use psr/log logger β†’ (Open) created by eiriksm
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    last update 5 months ago
    20 pass
  • Status changed to Needs review 5 months ago
  • πŸ‡³πŸ‡΄Norway eiriksm Norway
  • Pipeline finished with Success
    5 months ago
    Total: 212s
    #206779
  • Pipeline finished with Failed
    5 months ago
    Total: 201s
    #208693
  • Pipeline finished with Failed
    5 months ago
    Total: 194s
    #208704
  • Pipeline finished with Failed
    5 months ago
    Total: 283s
    #208987
  • Pipeline finished with Failed
    5 months ago
    #208994
  • Pipeline finished with Failed
    5 months ago
    Total: 281s
    #209010
  • Pipeline finished with Failed
    5 months ago
    Total: 221s
    #209020
  • Pipeline finished with Failed
    5 months ago
    Total: 291s
    #209023
  • Pipeline finished with Failed
    5 months ago
    Total: 290s
    #209030
  • Pipeline finished with Failed
    5 months ago
    #211534
  • Pipeline finished with Failed
    5 months ago
    Total: 188s
    #211586
  • Pipeline finished with Failed
    5 months ago
    #211598
  • Pipeline finished with Failed
    5 months ago
    Total: 266s
    #211606
  • Pipeline finished with Failed
    5 months ago
    Total: 306s
    #211615
  • Pipeline finished with Failed
    5 months ago
    Total: 270s
    #211741
  • Pipeline finished with Failed
    5 months ago
    #211744
  • Pipeline finished with Skipped
    5 months ago
    #211746
  • πŸ‡ΊπŸ‡¦Ukraine cosolom

    Maybe better to use latest version of Monolog? Looks like they fixed the issue https://www.drupal.org/project/monolog/issues/3366135 πŸ› NullLogger not implements LoggerChannelInterface Fixed

  • πŸ‡³πŸ‡΄Norway eiriksm Norway

    That would of course fix the issue described in the stack trace, but it's technically supported to use any and all implementations of the psr/log logger interface, including creating custom ones. So in my personal opinion it's more semantically and technically correct to use that as the type βœŒοΈπŸ€“

  • Pipeline finished with Success
    5 months ago
    Total: 179s
    #212770
  • Pipeline finished with Success
    5 months ago
    #213920
  • Pipeline finished with Success
    5 months ago
    Total: 530s
    #216997
  • Pipeline finished with Success
    5 months ago
    Total: 335s
    #217014
  • Pipeline finished with Success
    5 months ago
    Total: 346s
    #217139
  • Pipeline finished with Success
    5 months ago
    Total: 143s
    #217526
  • Pipeline finished with Success
    5 months ago
    Total: 306s
    #217863
  • Pipeline finished with Success
    5 months ago
    Total: 161s
    #217929
  • Pipeline finished with Failed
    5 months ago
    Total: 443s
    #220175
  • Pipeline finished with Failed
    5 months ago
    #220182
  • Pipeline finished with Failed
    5 months ago
    Total: 288s
    #220276
  • Pipeline finished with Canceled
    5 months ago
    Total: 87s
    #220377
  • Pipeline finished with Failed
    5 months ago
    Total: 307s
    #220378
  • Pipeline finished with Failed
    5 months ago
    Total: 280s
    #220385
  • Pipeline finished with Failed
    5 months ago
    Total: 287s
    #220397
  • Pipeline finished with Failed
    5 months ago
    #220407
  • Pipeline finished with Failed
    5 months ago
    #220430
  • Pipeline finished with Success
    5 months ago
    #220442
  • Pipeline finished with Success
    5 months ago
    #220460
  • Pipeline finished with Success
    4 months ago
    Total: 206s
    #226241
  • Pipeline finished with Failed
    4 months ago
    Total: 3698s
    #227493
  • Pipeline finished with Success
    4 months ago
    Total: 198s
    #228440
  • Pipeline finished with Canceled
    4 months ago
    Total: 76s
    #239131
  • Pipeline finished with Success
    4 months ago
    Total: 174s
    #239132
  • Pipeline finished with Failed
    4 months ago
    Total: 202s
    #244159
  • Pipeline finished with Success
    4 months ago
    #244167
  • Pipeline finished with Failed
    4 months ago
    Total: 220s
    #244191
  • Pipeline finished with Failed
    4 months ago
    Total: 185s
    #244258
  • Pipeline finished with Success
    4 months ago
    Total: 182s
    #244274
  • Pipeline finished with Success
    4 months ago
    Total: 83s
    #245274
  • Pipeline finished with Running
    4 months ago
    #245277
  • Pipeline finished with Canceled
    4 months ago
    Total: 77s
    #247498
  • Pipeline finished with Success
    4 months ago
    Total: 204s
    #247499
  • Pipeline finished with Success
    4 months ago
    Total: 327s
    #247517
  • Pipeline finished with Success
    3 months ago
    Total: 202s
    #249705
  • Pipeline finished with Success
    3 months ago
    Total: 318s
    #250057
  • Pipeline finished with Skipped
    3 months ago
    #250068
  • Pipeline finished with Success
    3 months ago
    Total: 328s
    #252912
  • Pipeline finished with Success
    3 months ago
    Total: 1018s
    #265101
  • Pipeline finished with Failed
    3 months ago
    Total: 354s
    #267230
  • Pipeline finished with Success
    3 months ago
    Total: 343s
    #267447
  • Pipeline finished with Skipped
    3 months ago
    #269317
  • Pipeline finished with Success
    3 months ago
    Total: 415s
    #274775
  • Pipeline finished with Success
    2 months ago
    Total: 229s
    #281995
  • Pipeline finished with Failed
    2 months ago
    Total: 225s
    #282163
  • Pipeline finished with Failed
    2 months ago
    Total: 222s
    #282172
  • Pipeline finished with Failed
    2 months ago
    Total: 222s
    #282293
  • Pipeline finished with Success
    2 months ago
    Total: 273s
    #282342
  • Pipeline finished with Running
    2 months ago
    #282374
  • Pipeline finished with Failed
    2 months ago
    Total: 279s
    #287035
  • Pipeline finished with Success
    about 2 months ago
    Total: 163s
    #293123
  • Pipeline finished with Skipped
    about 2 months ago
    #299119
  • Pipeline finished with Success
    about 2 months ago
    Total: 174s
    #299741
  • Pipeline finished with Success
    about 2 months ago
    Total: 277s
    #300523
  • Pipeline finished with Success
    about 1 month ago
    Total: 199s
    #304305
  • Pipeline finished with Failed
    about 1 month ago
    Total: 158s
    #314581
  • Pipeline finished with Failed
    about 1 month ago
    Total: 242s
    #315321
  • Pipeline finished with Failed
    about 1 month ago
    Total: 218s
    #315324
  • Pipeline finished with Success
    24 days ago
    Total: 242s
    #323677
  • Pipeline finished with Failed
    17 days ago
    Total: 461s
    #329563
  • Pipeline finished with Failed
    17 days ago
    Total: 200s
    #329571
  • Pipeline finished with Failed
    17 days ago
    Total: 172s
    #329576
  • Pipeline finished with Failed
    17 days ago
    Total: 168s
    #329578
  • Pipeline finished with Failed
    17 days ago
    Total: 266s
    #329586
  • Pipeline finished with Failed
    17 days ago
    Total: 215s
    #329592
  • Pipeline finished with Success
    17 days ago
    Total: 187s
    #329598
  • Pipeline finished with Failed
    17 days ago
    Total: 409s
    #329856
  • Pipeline finished with Failed
    12 days ago
    Total: 43s
    #334469
  • Pipeline finished with Failed
    12 days ago
    Total: 148s
    #334471
  • Pipeline finished with Failed
    9 days ago
    Total: 296s
    #337973
  • Pipeline finished with Failed
    8 days ago
    Total: 130s
    #337997
  • Pipeline finished with Failed
    8 days ago
    Total: 134s
    #338000
  • Pipeline finished with Failed
    8 days ago
    Total: 135s
    #338012
  • Pipeline finished with Failed
    8 days ago
    Total: 142s
    #338015
  • Pipeline finished with Failed
    8 days ago
    Total: 277s
    #338025
Production build 0.71.5 2024