Passed
Push — master ( 9ac357...f303b1 )
by Melech
01:29
created

PsrLogger::getExceptionTraceCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Log\Logger;
15
16
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Psr\Log\LoggerInterface;
18
use Throwable;
19
use Valkyrja\Log\Enum\LogLevel;
20
use Valkyrja\Log\Logger\Contract\LoggerContract as Contract;
21
use Valkyrja\Throwable\Handler\Abstract\ThrowableHandler;
22
23
class PsrLogger implements Contract
24
{
25
    public function __construct(
26
        protected LoggerInterface $logger
27
    ) {
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33
    #[Override]
34
    public function debug(string $message, array $context = []): void
35
    {
36
        $this->logger->debug($message, $context);
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    #[Override]
43
    public function info(string $message, array $context = []): void
44
    {
45
        $this->logger->info($message, $context);
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51
    #[Override]
52
    public function notice(string $message, array $context = []): void
53
    {
54
        $this->logger->notice($message, $context);
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    #[Override]
61
    public function warning(string $message, array $context = []): void
62
    {
63
        $this->logger->warning($message, $context);
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69
    #[Override]
70
    public function error(string $message, array $context = []): void
71
    {
72
        $this->logger->error($message, $context);
73
    }
74
75
    /**
76
     * @inheritDoc
77
     */
78
    #[Override]
79
    public function critical(string $message, array $context = []): void
80
    {
81
        $this->logger->critical($message, $context);
82
    }
83
84
    /**
85
     * @inheritDoc
86
     */
87
    #[Override]
88
    public function alert(string $message, array $context = []): void
89
    {
90
        $this->logger->alert($message, $context);
91
    }
92
93
    /**
94
     * @inheritDoc
95
     */
96
    #[Override]
97
    public function emergency(string $message, array $context = []): void
98
    {
99
        $this->logger->emergency($message, $context);
100
    }
101
102
    /**
103
     * @inheritDoc
104
     */
105
    #[Override]
106
    public function log(LogLevel $level, string $message, array $context = []): void
107
    {
108
        $this->logger->log($level->value, $message, $context);
109
    }
110
111
    /**
112
     * @inheritDoc
113
     */
114
    #[Override]
115
    public function throwable(Throwable $throwable, string $message, array $context = []): void
116
    {
117
        $traceCode  = ThrowableHandler::getTraceCode($throwable);
118
        $logMessage = "\nTrace Code: $traceCode"
119
            . "\nException Message: {$throwable->getMessage()}"
120
            . "\nMessage: $message"
121
            . "\nStack Trace:"
122
            . "\n=================================="
123
            . "\n{$throwable->getTraceAsString()}"
124
            . "\n==================================\n";
125
126
        $this->error($logMessage, $context);
127
    }
128
}
129