LogTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 8
eloc 19
c 3
b 0
f 0
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A logInfo() 0 7 2
A logWarning() 0 7 2
A logDebug() 0 7 2
A logError() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Traits;
6
7
use WebServCo\Framework\Interfaces\OutputLoggerInterface;
8
9
/**
10
* Log simple messages to both file and output.
11
*/
12
trait LogTrait
13
{
14
    protected \WebServCo\Framework\Interfaces\LoggerInterface $fileLogger;
15
    protected ?OutputLoggerInterface $outputLogger = null;
16
17
    /**
18
    * @param mixed $context
19
    */
20
    protected function logDebug(string $message, $context = []): void
21
    {
22
        $this->fileLogger->debug($message, $context);
23
        if (!$this->outputLogger instanceof OutputLoggerInterface) {
24
            return;
25
        }
26
        $this->outputLogger->output($message);
27
    }
28
29
    /**
30
    * @param mixed $context
31
    */
32
    protected function logError(string $message, $context = []): void
33
    {
34
        $this->fileLogger->error($message, $context);
35
        if (!$this->outputLogger instanceof OutputLoggerInterface) {
36
            return;
37
        }
38
        $this->outputLogger->output($message);
39
    }
40
41
    /**
42
    * @param mixed $context
43
    */
44
    protected function logInfo(string $message, $context = []): void
45
    {
46
        $this->fileLogger->info($message, $context);
47
        if (!$this->outputLogger instanceof OutputLoggerInterface) {
48
            return;
49
        }
50
        $this->outputLogger->output($message);
51
    }
52
53
    /**
54
    * @param mixed $context
55
    */
56
    protected function logWarning(string $message, $context = []): void
57
    {
58
        $this->fileLogger->warning($message, $context);
59
        if (!$this->outputLogger instanceof OutputLoggerInterface) {
60
            return;
61
        }
62
        $this->outputLogger->output($message);
63
    }
64
}
65