1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oqq\Minc\Log; |
4
|
|
|
|
5
|
|
|
use Psr\Log\AbstractLogger; |
6
|
|
|
use Psr\Log\InvalidArgumentException; |
7
|
|
|
use Oqq\Minc\Log\Handler\HandlerContainerInterface; |
8
|
|
|
use Oqq\Minc\Log\Handler\HandlerContainerTrait; |
9
|
|
|
use Oqq\Minc\Log\Processor\ProcessorContainerInterface; |
10
|
|
|
use Oqq\Minc\Log\Processor\ProcessorContainerTrait; |
11
|
|
|
use Oqq\Minc\Log\Handler\HandlerInterface; |
12
|
|
|
use Oqq\Minc\Log\Processor\ProcessorInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Eric Braun <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class Logger extends AbstractLogger implements LoggerInterface, HandlerContainerInterface, ProcessorContainerInterface |
18
|
|
|
{ |
19
|
|
|
use HandlerContainerTrait; |
20
|
|
|
use ProcessorContainerTrait; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $channel; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $channel |
27
|
|
|
* @param HandlerInterface[] $handlers |
28
|
|
|
* @param ProcessorInterface[] $processors |
29
|
|
|
*/ |
30
|
14 |
|
public function __construct( |
31
|
|
|
$channel = LoggerInterface::DEFAULT_CHANNEL, |
32
|
|
|
array $handlers = [], |
33
|
|
|
array $processors = [] |
34
|
|
|
) { |
35
|
14 |
|
$this->channel = $channel; |
36
|
|
|
|
37
|
14 |
|
$this->setHandlers($handlers); |
38
|
14 |
|
$this->setProcessors($processors); |
39
|
14 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
13 |
|
public function getChannel() |
45
|
|
|
{ |
46
|
13 |
|
return $this->channel; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
* |
52
|
|
|
* @throws InvalidArgumentException |
53
|
|
|
*/ |
54
|
13 |
|
public function log($levelName, $message, array $context = []) |
55
|
|
|
{ |
56
|
13 |
|
$record = new Record($this->getChannel(), (string) $message, Level::createFromName($levelName)); |
57
|
12 |
|
$record->setContext($context); |
58
|
|
|
|
59
|
12 |
|
$this->applyProcessors($record); |
60
|
|
|
|
61
|
12 |
|
foreach ($this->handlers as $handler) { |
62
|
12 |
|
$pass = $handler->handle($record); |
63
|
|
|
|
64
|
12 |
|
if (true !== $pass) { |
65
|
|
|
break; |
66
|
|
|
} |
67
|
12 |
|
} |
68
|
12 |
|
} |
69
|
|
|
} |
70
|
|
|
|