Restore logging for cache operations

`AbstractCache` exposes the ability to set a logger. Default behavior
automatically passes the logger reference down to the cache, unless a
specific cache instance was provided.
This commit is contained in:
Amit Snyderman
2013-09-05 19:22:13 -04:00
parent 94cd72bfd4
commit 724cd60cac
5 changed files with 65 additions and 9 deletions
+27
View File
@@ -0,0 +1,27 @@
<?php
abstract class Mustache_Cache_AbstractCache implements Mustache_Cache
{
private $logger = null;
public function getLogger()
{
return $this->logger;
}
public function setLogger($logger = null)
{
if ($logger !== null && !($logger instanceof Mustache_Logger || is_a($logger, 'Psr\\Log\\LoggerInterface'))) {
throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.');
}
$this->logger = $logger;
}
protected function log($level, $message, array $context = array())
{
if (isset($this->logger)) {
$this->logger->log($level, $message, $context);
}
}
}