Passed
Push — master ( 2e496e...4c080f )
by Alexander
03:20 queued 01:17
created

PsrTarget::export()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Log;
6
7
use Psr\Log\LoggerInterface;
8
9
/**
10
 * PsrTarget is a log target which simply passes messages to another PSR-3 compatible logger.
11
 */
12
final class PsrTarget extends Target
13
{
14
    /**
15
     * @var LoggerInterface The logger instance to be used for messages processing.
16
     */
17
    private LoggerInterface $logger;
18
19
    /**
20
     * Sets the PSR-3 logger used to save messages of this target.
21
     *
22
     * @param LoggerInterface $logger The logger instance.
23
     */
24 8
    public function __construct(LoggerInterface $logger)
25
    {
26 8
        $this->logger = $logger;
27 8
        parent::__construct();
28 8
    }
29
30
    /**
31
     * @return LoggerInterface The logger instance.
32
     */
33 8
    public function getLogger(): LoggerInterface
34
    {
35 8
        return $this->logger;
36
    }
37
38 8
    public function export(): void
39
    {
40 8
        foreach ($this->getMessages() as $message) {
41 8
            [$level, $text, $context] = $message;
42 8
            $this->logger->log($level, $text, $context);
43
        }
44 8
    }
45
}
46