AutoLoggerTrait::log()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 3
crap 6
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