AutoLoggerTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 47
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 4 1
A getLogger() 0 4 1
A log() 0 6 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/skeleton/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/skeleton
7
 */
8
9
namespace Flipbox\Skeleton\Logger;
10
11
use Psr\Log\LoggerInterface;
12
use Psr\Log\LoggerTrait;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.0.0
17
 */
18
trait AutoLoggerTrait
19
{
20
21
    use LoggerTrait;
22
23
    /**
24
     * The logger instance.
25
     *
26
     * @var LoggerInterface
27
     */
28
    private $logger;
29
30
    /**
31
     * Set a logger
32
     *
33
     * @param LoggerInterface $logger
34
     */
35
    public function setLogger(LoggerInterface $logger)
36
    {
37
        $this->logger = $logger;
38
    }
39
40
    /**
41
     * Get a logger
42
     *
43
     * @return LoggerInterface|null
44
     */
45
    public function getLogger()
46
    {
47
        return $this->logger;
48
    }
49
50
    /**
51
     * Logs with an arbitrary level.
52
     *
53
     * @param mixed $level
54
     * @param string $message
55
     * @param array $context
56
     *
57
     */
58
    public function log($level, $message, array $context = [])
59
    {
60
        if ($this->getLogger()) {
61
            $this->getLogger()->log($level, $message, $context);
62
        }
63
    }
64
}
65