PHP Fatal error: Declaration of Drupal\monolog\Logger\Logger::addRecord must be compatible with Monolog\Logger::addRecord in /app/web/modules/contrib/monolog/src/Logger/Logger.php

Created on 18 August 2023, 10 months ago

Problem/Motivation

Installing monolog module in Drupal 9 and trying to use any drush command caused the following error:
PHP Fatal error: Declaration of Drupal\monolog\Logger\Logger::addRecord(int $level, string $message, array $context = []): bool must be compatible with Monolog\Logger::addRecord(int $level, string $message, array $context = [], ?Monolog\DateTimeImmutable $datetime = null): bool in /app/web/modules/contrib/monolog/src/Logger/Logger.php on line 41

Steps to reproduce

Install monolog 2.2.0 on Drupal 9 and afterwards try using any Drush command.

Proposed resolution

Add ?Monolog\DateTimeImmutable $datetime = null to the addRecord method in Drupal\monolog\Logger\Logger

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

2.2

Component

Code

Created by

🇱🇻Latvia deiviic Riga

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

Comments & Activities

  • Issue created by @deiviic
  • First commit to issue fork.
  • Assigned to viren18febS
  • 🇮🇳India viren18febS

    Checking the issue!

  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
  • 🇮🇳India viren18febS

    it's working for me. I have checked the issue with monolog 2.2.0 on Drupal 9.5. after setup all the configuration's for log file, I am not getting any error related to logging & it's successfully writes the logs in private folder.

    Please refer the module help for configurations.

Production build 0.69.0 2024