Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
LoggerTrait | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
getLogger | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setLogger | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
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 8+ |
8 | * |
9 | * @package Banker |
10 | * @author Timothy J. Warren <tim@timshomepage.net> |
11 | * @copyright 2016 - 2023 Timothy J. Warren |
12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
13 | * @version 4.1.0 |
14 | * @link https://git.timshomepage.net/timw4mail/banker |
15 | */ |
16 | namespace Aviat\Banker; |
17 | |
18 | use Psr\Log\{ |
19 | LoggerAwareTrait, |
20 | LoggerInterface, |
21 | LogLevel, |
22 | NullLogger |
23 | }; |
24 | |
25 | /** |
26 | * Trait for keeping track of logger objects |
27 | */ |
28 | trait LoggerTrait { |
29 | |
30 | use LoggerAwareTrait; |
31 | |
32 | /** |
33 | * Return the existing logger instance or |
34 | * a NullLogger, if no instance set |
35 | */ |
36 | protected function getLogger(): LoggerInterface |
37 | { |
38 | if ($this->logger === NULL) |
39 | { |
40 | $this->logger = new NullLogger(); |
41 | } |
42 | return $this->logger; |
43 | } |
44 | |
45 | /** |
46 | * Set a logger to keep track of errors |
47 | */ |
48 | public function setLogger(LoggerInterface $logger): void |
49 | { |
50 | $this->logger = $logger; |
51 | |
52 | // Set the logger for the current driver too |
53 | if (isset($this->driver)) |
54 | { |
55 | $this->driver->setLogger($logger); |
56 | } |
57 | } |
58 | } |