Description
Symfony version(s) affected
6.2.0
Description
When a CacheAdapter logs an error using CacheItem::log()
, an array with context information is provided. Often this array also include the 'cache-adapter' => get_debug_type($this)
to handover the name of the cache adapter to the error message, which is useful when multiple CacheAdapters are involved.
However, since the message itself does not contain the cache-adapter
placeholder, this information is not included in the eventual error message.
When a PSR Logger is assigned to the CacheAdapter, this might not be a big problem (since the context is handed over and used in another way). But when trigger_error
is used, this information is really lost.
How to reproduce
Have a CacheAdapter log a messages using CacheItem::log() and check whether the name of the CacheAdapter end up in the error message of the logs.
Possible Solution
Include {cache-adapter}
placeholder in the error message, for example:
$message = sprintf('Failed to save key "{key}" of type %s%s to CacheAdapter "{cache-adapter}"', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]);
Additional Context
No response