Passed
Pull Request — master (#1779)
by Nico
49:51 queued 23:55
created

PirateLogger::logf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Logging;
6
7
use Monolog\Handler\RotatingFileHandler;
8
use Monolog\Logger;
9
use Stu\Module\Config\StuConfigInterface;
10
11
final class PirateLogger implements PirateLoggerInterface
12
{
13
    private ?Logger $logger = null;
14
15
    public function __construct(private StuConfigInterface $stuConfig)
16
    {
17
    }
18
19
    public function initRotating(): void
20
    {
21
        $this->logger = new Logger('KAZON');
22
        $this->logger->pushHandler(
23
            new RotatingFileHandler(
24
                $this->stuConfig->getGameSettings()->getPirateLogfilePath()
25
            ),
26
        );
27
    }
28
29
    public function log(string $message): void
30
    {
31
        $method = LoggerEnum::LEVEL_METHODS[LoggerEnum::LEVEL_INFO];
32
        $this->logger->$method($message);
33
    }
34
35
    public function logf(string $information, ...$args): void
36
    {
37
        $this->log(vsprintf(
38
            $information,
39
            $args
40
        ));
41
    }
42
}
43