1
0
Fork 0

Fix context info being missing from output when using the IO classes as PSR-3 logger, fixes #11882

pull/11885/head
Jordi Boggiano 2024-03-11 17:23:06 +01:00
parent 96f757f3a4
commit 2124f09d75
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 8 additions and 0 deletions

View File

@ -15,6 +15,7 @@ namespace Composer\IO;
use Composer\Config; use Composer\Config;
use Composer\Pcre\Preg; use Composer\Pcre\Preg;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\Silencer;
use Psr\Log\LogLevel; use Psr\Log\LogLevel;
abstract class BaseIO implements IOInterface abstract class BaseIO implements IOInterface
@ -219,6 +220,13 @@ abstract class BaseIO implements IOInterface
{ {
$message = (string) $message; $message = (string) $message;
if ($context !== []) {
$json = Silencer::call('json_encode', $context, JSON_INVALID_UTF8_IGNORE|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
if ($json !== false) {
$message .= ' ' . $json;
}
}
if (in_array($level, [LogLevel::EMERGENCY, LogLevel::ALERT, LogLevel::CRITICAL, LogLevel::ERROR])) { if (in_array($level, [LogLevel::EMERGENCY, LogLevel::ALERT, LogLevel::CRITICAL, LogLevel::ERROR])) {
$this->writeError('<error>'.$message.'</error>'); $this->writeError('<error>'.$message.'</error>');
} elseif ($level === LogLevel::WARNING) { } elseif ($level === LogLevel::WARNING) {