I think this is a compatibility issue with
- composer
- monolog (as in composer's version)
- using monolog in the application - the latest version
- and running a script in composer.json, which invokes monolog
aside from the composer.json listed below, this test script is being called from the composer.json file post-update
I was able to set up a test environment with just the 2 files - test.php and composer.json, and run composer u, you can see the issue at the bottom of the output
if monolog is set to less than 3, there is no problem
the problem is the same if I run composer self-update, I use wsl and Alpine linux as my dev environment
cheers - thanks for a great product !
test.php
<?php
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Logger;
abstract class test {
static function demo() {
$monolog = new Logger('demo');
$syslog = new ErrorLogHandler;
$formatter = new LineFormatter("%channel%.%level_name%: %message% %context%");
$syslog->setFormatter($formatter);
$monolog->pushHandler($syslog);
$monolog->info('hello world');
}
}
My composer.json:
{
"license": "MIT",
"autoload": {
"psr-4": {
"": "."
}
},
"require": {
"monolog/monolog": "^3.2"
},
"scripts": {
"post-update-cmd": [
"test::demo"
]
}
}
Output of composer diagnose:
Checking composer.json: WARNING
Defining autoload.psr-4 with an empty namespace prefix is a bad idea for performance
Checking platform settings: OK
Checking git settings: No git process found
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: FAIL
Missing pubkey for tags verification
Missing pubkey for dev verification
Run composer self-update --update-keys to set them up
Checking composer version: You are not running the latest stable version, run `composer self-update` to update (2.4.4 => 2.5.1)
Composer version: 2.4.4
PHP version: 8.1.13
PHP binary path: /usr/bin/php81
OpenSSL version: OpenSSL 3.0.7 1 Nov 2022
cURL version: 7.87.0 libz 1.2.13 ssl OpenSSL/3.0.7
zip: extension present, unzip present, 7-Zip not available
When I run this command:
I get the following output:
Running 2.4.4 (2022-10-27 14:39:29) with PHP 8.1.13 on Linux / 5.15.79.1-microsoft-standard-WSL2
Reading ./composer.json (/mnt/c/Users/davbr/GitHub/tmonolog/composer.json)
Loading config file ./composer.json (/mnt/c/Users/davbr/GitHub/tmonolog/composer.json)
Checked CA file /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/mnt/c/Users/davbr/GitHub/tmonolog): 'git' 'branch' '-a' '--no-color' '--no-abbrev' '-v'
Executing command (/mnt/c/Users/davbr/GitHub/tmonolog): git describe --exact-match --tags
Executing command (CWD): git --version
Executing command (/mnt/c/Users/davbr/GitHub/tmonolog): git log --pretty="%H" -n1 HEAD
Executing command (/mnt/c/Users/davbr/GitHub/tmonolog): hg branch
Executing command (/mnt/c/Users/davbr/GitHub/tmonolog): fossil branch list
Executing command (/mnt/c/Users/davbr/GitHub/tmonolog): fossil tag list
Executing command (/mnt/c/Users/davbr/GitHub/tmonolog): svn info --xml
Running cache garbage collection
Failed to initialize global composer: Composer could not find the config file: /home/davbr/.config/composer/composer.json
Reading ./composer.lock (/mnt/c/Users/davbr/GitHub/tmonolog/composer.lock)
Reading /mnt/c/Users/davbr/GitHub/tmonolog/vendor/composer/installed.json
Loading composer repositories with package information
Reading /home/davbr/.cache/composer/repo/https---repo.packagist.org/packages.json from cache
Downloading https://repo.packagist.org/packages.json if modified
[200] https://repo.packagist.org/packages.json
Info from https://repo.packagist.org: #StandWithUkraine
Writing /home/davbr/.cache/composer/repo/https---repo.packagist.org/packages.json into cache
Reading /home/davbr/.cache/composer/repo/https---repo.packagist.org/provider-monolog~monolog.json from cache
Downloading https://repo.packagist.org/p2/monolog/monolog.json if modified
[304] https://repo.packagist.org/p2/monolog/monolog.json
Reading /home/davbr/.cache/composer/repo/https---repo.packagist.org/provider-psr~log.json from cache
Downloading https://repo.packagist.org/p2/psr/log.json if modified
[304] https://repo.packagist.org/p2/psr/log.json
Built pool.
Running pool optimizer.
Pool optimizer completed in 0.003 seconds
Found 46 package versions referenced in your dependency graph. 1 (2%) were optimized away.
Updating dependencies
Generating rules
Resolving dependencies through SAT
Looking at all rules.
Dependency resolution completed in 0.000 seconds
Analyzed 45 packages to resolve dependencies
Analyzed 47 rules to resolve dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
> post-update-cmd: test::demo
PHP Fatal error: Declaration of Monolog\Logger::emergency(Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::emergency($message, array $context = []) in /mnt/c/Users/davbr/GitHub/tmonolog/vendor/monolog/monolog/src/Monolog/Logger.php on line 651
Fatal error: Declaration of Monolog\Logger::emergency(Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::emergency($message, array $context = []) in /mnt/c/Users/davbr/GitHub/tmonolog/vendor/monolog/monolog/src/Monolog/Logger.php on line 651
And I expected this to happen:
I think this is a compatibility issue with
aside from the composer.json listed below, this test script is being called from the composer.json file post-update
I was able to set up a test environment with just the 2 files - test.php and composer.json, and run composer u, you can see the issue at the bottom of the output
if monolog is set to less than 3, there is no problem
the problem is the same if I run composer self-update, I use wsl and Alpine linux as my dev environment
cheers - thanks for a great product !
test.php
My
composer.json:{ "license": "MIT", "autoload": { "psr-4": { "": "." } }, "require": { "monolog/monolog": "^3.2" }, "scripts": { "post-update-cmd": [ "test::demo" ] } }Output of
composer diagnose:When I run this command:
I get the following output:
And I expected this to happen: