InMemoryLogger::log()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace SubjectivePHP\Psr\Log;
4
5
use ArrayObject;
6
use Psr\Log\AbstractLogger;
7
use Psr\Log\LoggerInterface;
8
9
/**
10
 * PSR-3 Logger implementation writing to an array.
11
 */
12
final class InMemoryLogger extends AbstractLogger implements LoggerInterface
13
{
14
    use MessageInterpolationTrait;
15
16
    /**
17
     * @var ArrayObject
18
     */
19
    private $logs;
20
21
    /**
22
     * Construct a new instance of the logger.
23
     *
24
     * @param ArrayObject $logs Container for log entries.
25
     */
26
    public function __construct(ArrayObject $logs)
27
    {
28
        $this->logs = $logs;
29
    }
30
31
    /**
32
     * Logs with an arbitrary level.
33
     *
34
     * @param string $level   A valid RFC-5424 log level.
35
     * @param string $message The base log message.
36
     * @param array  $context Any extraneous information that does not fit well in a string.
37
     *
38
     * @return void
39
     */
40
    public function log($level, $message, array $context = [])
41
    {
42
        $this->logs[] = [
43
            'level' => $level,
44
            'message' => $this->interpolateMessage($message, $context),
45
            'context' => $context,
46
        ];
47
    }
48
}
49