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