[Cache] Added context to log messages
This commit is contained in:
parent
b2f210f1f3
commit
a4d9e0fc94
@ -166,7 +166,7 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
|
|||||||
$v = $values[$id];
|
$v = $values[$id];
|
||||||
$type = get_debug_type($v);
|
$type = get_debug_type($v);
|
||||||
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
||||||
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
|
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($values as $id => $v) {
|
foreach ($values as $id => $v) {
|
||||||
@ -189,7 +189,7 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
|
|||||||
$ok = false;
|
$ok = false;
|
||||||
$type = get_debug_type($v);
|
$type = get_debug_type($v);
|
||||||
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
||||||
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
|
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
|
|||||||
$v = $values[$id];
|
$v = $values[$id];
|
||||||
$type = get_debug_type($v);
|
$type = get_debug_type($v);
|
||||||
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
||||||
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
|
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($values as $id => $v) {
|
foreach ($values as $id => $v) {
|
||||||
@ -220,7 +220,7 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
|
|||||||
$ok = false;
|
$ok = false;
|
||||||
$type = get_debug_type($v);
|
$type = get_debug_type($v);
|
||||||
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
||||||
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
|
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
$message = 'Failed to delete key "{key}"'.($e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
$message = 'Failed to delete key "{key}"'.($e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
||||||
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]);
|
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
$ok = false;
|
$ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$type = get_debug_type($value);
|
$type = get_debug_type($value);
|
||||||
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
|
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
|
||||||
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]);
|
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -375,7 +375,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
|
|||||||
try {
|
try {
|
||||||
$value = unserialize($value);
|
$value = unserialize($value);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
CacheItem::log($this->logger, 'Failed to unserialize key "{key}": '.$e->getMessage(), ['key' => $key, 'exception' => $e]);
|
CacheItem::log($this->logger, 'Failed to unserialize key "{key}": '.$e->getMessage(), ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
$value = false;
|
$value = false;
|
||||||
}
|
}
|
||||||
if (false === $value) {
|
if (false === $value) {
|
||||||
|
@ -6,6 +6,7 @@ CHANGELOG
|
|||||||
|
|
||||||
* added max-items + LRU + max-lifetime capabilities to `ArrayCache`
|
* added max-items + LRU + max-lifetime capabilities to `ArrayCache`
|
||||||
* added `CouchbaseBucketAdapter`
|
* added `CouchbaseBucketAdapter`
|
||||||
|
* added context `cache-adapter` to log messages
|
||||||
|
|
||||||
5.0.0
|
5.0.0
|
||||||
-----
|
-----
|
||||||
|
@ -107,7 +107,7 @@ trait AbstractAdapterTrait
|
|||||||
try {
|
try {
|
||||||
return $this->doHave($id);
|
return $this->doHave($id);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
CacheItem::log($this->logger, 'Failed to check if key "{key}" is cached: '.$e->getMessage(), ['key' => $key, 'exception' => $e]);
|
CacheItem::log($this->logger, 'Failed to check if key "{key}" is cached: '.$e->getMessage(), ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ trait AbstractAdapterTrait
|
|||||||
try {
|
try {
|
||||||
return $this->doClear($namespaceToClear) || $cleared;
|
return $this->doClear($namespaceToClear) || $cleared;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
CacheItem::log($this->logger, 'Failed to clear the cache: '.$e->getMessage(), ['exception' => $e]);
|
CacheItem::log($this->logger, 'Failed to clear the cache: '.$e->getMessage(), ['exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ trait AbstractAdapterTrait
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
$message = 'Failed to delete key "{key}"'.($e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
$message = 'Failed to delete key "{key}"'.($e instanceof \Exception ? ': '.$e->getMessage() : '.');
|
||||||
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]);
|
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
$ok = false;
|
$ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ trait AbstractAdapterTrait
|
|||||||
|
|
||||||
return $f($key, $value, $isHit);
|
return $f($key, $value, $isHit);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
CacheItem::log($this->logger, 'Failed to fetch key "{key}": '.$e->getMessage(), ['key' => $key, 'exception' => $e]);
|
CacheItem::log($this->logger, 'Failed to fetch key "{key}": '.$e->getMessage(), ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $f($key, null, false);
|
return $f($key, null, false);
|
||||||
@ -244,7 +244,7 @@ trait AbstractAdapterTrait
|
|||||||
try {
|
try {
|
||||||
$items = $this->doFetch($ids);
|
$items = $this->doFetch($ids);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
CacheItem::log($this->logger, 'Failed to fetch items: '.$e->getMessage(), ['keys' => $keys, 'exception' => $e]);
|
CacheItem::log($this->logger, 'Failed to fetch items: '.$e->getMessage(), ['keys' => $keys, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
$items = [];
|
$items = [];
|
||||||
}
|
}
|
||||||
$ids = array_combine($ids, $keys);
|
$ids = array_combine($ids, $keys);
|
||||||
@ -347,7 +347,7 @@ trait AbstractAdapterTrait
|
|||||||
yield $key => $f($key, $value, true);
|
yield $key => $f($key, $value, true);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
CacheItem::log($this->logger, 'Failed to fetch items: '.$e->getMessage(), ['keys' => array_values($keys), 'exception' => $e]);
|
CacheItem::log($this->logger, 'Failed to fetch items: '.$e->getMessage(), ['keys' => array_values($keys), 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
|
Reference in New Issue
Block a user