Pierre-Lannoy / wp-decalog

Capture and log events, metrics and traces on your site. Make WordPress observable - finally!
https://perfops.one/
GNU General Public License v3.0
64 stars 8 forks source link

PHP Fatal error: Declaration of Decalog\Logger::emergency must be compatible with Psr\Log\LoggerInterface::emergency #65

Closed kodie closed 2 months ago

kodie commented 2 months ago

Describe the bug Installing DecaLog on a fresh WordPress install with no other plugins activated throws the following errors and basically stops the entire site from working with the classic "There has been a critical error on this website. Learn more about troubleshooting WordPress" message. It does appear that it creates a mu-plugins directory with a _decalog_loader.php file in it as well as a fatal-error-handler.php file in the content directory.

Errors:

[25-Jun-2024 15:38:11 UTC] PHP Fatal error:  Declaration of Decalog\Logger::emergency($message, $context = []) must be compatible with Psr\Log\LoggerInterface::emergency(Stringable|string $message, array $context = []): void in /app/content/plugins/decalog/includes/api/class-logger.php on line 242
[25-Jun-2024 15:38:11 UTC] PHP Fatal error:  Declaration of Decalog\Logger::emergency($message, $context = []) must be compatible with Psr\Log\LoggerInterface::emergency(Stringable|string $message, array $context = []): void in /app/content/plugins/decalog/includes/api/class-logger.php on line 242
[25-Jun-2024 15:38:11 UTC] PHP Notice:  Function is_embed was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see <a>Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in /app/wordpress/wp-includes/functions.php on line 6078
[25-Jun-2024 15:38:11 UTC] PHP Notice:  Function is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see <a>Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in /app/wordpress/wp-includes/functions.php on line 6078

To Reproduce

  1. Spin up a fresh copy of WordPress
  2. Install/Activate DecaLog
  3. See error

Environment (please complete the following information):

Additional context Our WordPress environment is slightly unique I guess in the sense that we are running it inside of a docker container, install WordPress core and plugins via Composer, our WP core is installed to it's own directory ("wordpress"), and our wp-content directory is just called "content".

Example:

/content
  /plugins
  /themes
  /uploads
/vendor
/wordpress
  /wp-admin
  /wp-includes
composer.json
index.php
wp-config.php
kodie commented 2 months ago

Something to add here. I found that adding "psr/log": "^2" to the composer dependencies fixes the issue, but then the plugin has some notices about it running in "PSR-3 v1 compatibility mode".

Pierre-Lannoy commented 2 months ago

Hello @kodie ! Could you confirm it's on a fresh install of WordPress you have such an error. How do you have a composer.json ?

kodie commented 2 months ago

Yes, fresh install where DecaLog is the only plugin active.

composer.json looks something like this:

{
  "name": "kodie/new-project",
  "repositories":[
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    }
  ],
  "config": {
    "allow-plugins": {
      "composer/installers": true,
      "johnpbloch/wordpress-core-installer": true
    }
  },
  "extra": {
    "wordpress-install-dir": "wordpress",
    "installer-paths": {
      "content/plugins/{$name}/": ["type:wordpress-plugin"]
    }
  },
  "require": {
    "php": ">=8.1",
    "johnpbloch/wordpress": "6.5.4",
    "wpackagist-plugin/decalog": "4.2.0",
    "psr/log": "^2"
  },
  "require-dev": {
    "itsahappymedium/fec": "0.2.2",
    "itsahappymedium/gpm": "0.1.1",
    "itsahappymedium/wp-deployer": "0.4.1"
  }
}
Pierre-Lannoy commented 2 months ago

OK. So it's normal. If you install WP with wpackagist/composer its behavior is different. Definitely not a "vanilla" WordPress. If you chose to install it like that, and in order to not change your composer.json (please, please don't use PSR-3 v2), you have to follow this to force PSR-3 v3.

kodie commented 2 months ago

Can confirm that adding define('DECALOG_PSR_LOG_VERSION', 'AUTO'); to wp-config.php fixed the issue for me! Thank you!