PsrTarget   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 26
ccs 8
cts 8
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getLogger() 0 3 1
A export() 0 6 2
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
     * Sets the PSR-3 logger used to save messages of this target.
16
     *
17
     * @param LoggerInterface $logger The logger instance to be used for messages processing.
18
     */
19 8
    public function __construct(private LoggerInterface $logger)
20
    {
21 8
        parent::__construct();
22
    }
23
24
    /**
25
     * @return LoggerInterface The logger instance.
26
     */
27 8
    public function getLogger(): LoggerInterface
28
    {
29 8
        return $this->logger;
30
    }
31
32 8
    protected function export(): void
33
    {
34 8
        foreach ($this->getMessages() as $message) {
35
            /** @var array $context */
36 8
            $context = $message->context();
37 8
            $this->logger->log($message->level(), $message->message(), $context);
38
        }
39
    }
40
}
41