From 2124f09d75167449e9efa8ae3e2d8ad034e64bdb Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 11 Mar 2024 17:23:06 +0100 Subject: [PATCH] Fix context info being missing from output when using the IO classes as PSR-3 logger, fixes #11882 --- src/Composer/IO/BaseIO.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Composer/IO/BaseIO.php b/src/Composer/IO/BaseIO.php index 710f5a108..c4d40ba01 100644 --- a/src/Composer/IO/BaseIO.php +++ b/src/Composer/IO/BaseIO.php @@ -15,6 +15,7 @@ namespace Composer\IO; use Composer\Config; use Composer\Pcre\Preg; use Composer\Util\ProcessExecutor; +use Composer\Util\Silencer; use Psr\Log\LogLevel; abstract class BaseIO implements IOInterface @@ -219,6 +220,13 @@ abstract class BaseIO implements IOInterface { $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])) { $this->writeError(''.$message.''); } elseif ($level === LogLevel::WARNING) {