Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
7 / 7
LoggerTrait
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
7 / 7
 getLogger
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 setLogger
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
<?php declare(strict_types=1);
/**
 * Banker
 *
 * A Caching library implementing psr/cache (PSR 6) and psr/simple-cache (PSR 16)
 *
 * PHP version 7.4
 *
 * @package     Banker
 * @author      Timothy J. Warren <tim@timshomepage.net>
 * @copyright   2016 - 2020  Timothy J. Warren
 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
 * @version     3.1.0
 * @link        https://git.timshomepage.net/timw4mail/banker
 */
namespace Aviat\Banker;
use Psr\Log\{
    LoggerAwareTrait,
    LoggerInterface,
    LogLevel,
    NullLogger
};
/**
 * Trait for keeping track of logger objects
 */
trait LoggerTrait {
    use LoggerAwareTrait;
    /**
     * Return the existing logger instance or
     * a NullLogger, if no instance set
     *
     * @return LoggerInterface
     */
    protected function getLogger(): LoggerInterface
    {
        if ($this->logger === NULL)
        {
            $this->logger = new NullLogger();
        }
        return $this->logger;
    }
    /**
     * Set a logger to keep track of errors
     *
     * @param LoggerInterface $logger
     * @return self
     */
    public function setLogger(LoggerInterface $logger): self
    {
        $this->logger = $logger;
        // Set the logger for the current driver too
        if (isset($this->driver))
        {
            $this->driver->setLogger($logger);
        }
        return $this;
    }
}