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
1<?php declare(strict_types=1);
2/**
3 * Banker
4 *
5 * A Caching library implementing psr/cache (PSR 6) and psr/simple-cache (PSR 16)
6 *
7 * PHP version 7.4
8 *
9 * @package     Banker
10 * @author      Timothy J. Warren <tim@timshomepage.net>
11 * @copyright   2016 - 2020  Timothy J. Warren
12 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
13 * @version     3.1.0
14 * @link        https://git.timshomepage.net/timw4mail/banker
15 */
16namespace Aviat\Banker;
17
18use Psr\Log\{
19    LoggerAwareTrait,
20    LoggerInterface,
21    LogLevel,
22    NullLogger
23};
24
25/**
26 * Trait for keeping track of logger objects
27 */
28trait LoggerTrait {
29
30    use LoggerAwareTrait;
31
32    /**
33     * Return the existing logger instance or
34     * a NullLogger, if no instance set
35     *
36     * @return LoggerInterface
37     */
38    protected function getLogger(): LoggerInterface
39    {
40        if ($this->logger === NULL)
41        {
42            $this->logger = new NullLogger();
43        }
44        return $this->logger;
45    }
46
47    /**
48     * Set a logger to keep track of errors
49     *
50     * @param LoggerInterface $logger
51     * @return self
52     */
53    public function setLogger(LoggerInterface $logger): self
54    {
55        $this->logger = $logger;
56
57        // Set the logger for the current driver too
58        if (isset($this->driver))
59        {
60            $this->driver->setLogger($logger);
61        }
62
63        return $this;
64    }
65}