|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Bushido\Foundation package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Wojciech Nowicki <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Bushido\Foundation\Helpers; |
|
12
|
|
|
|
|
13
|
|
|
use Psr\Log\LoggerInterface; |
|
14
|
|
|
use Psr\Log\LogLevel; |
|
15
|
|
|
|
|
16
|
|
|
trait PsrLoggerTrait |
|
17
|
|
|
{ |
|
18
|
|
|
abstract protected function getLogger(): ?LoggerInterface; |
|
19
|
|
|
|
|
20
|
3 |
|
protected function logEmergency(string $message, array $context = []): void |
|
21
|
|
|
{ |
|
22
|
3 |
|
$this->log(LogLevel::EMERGENCY, $message, $context); |
|
23
|
3 |
|
} |
|
24
|
|
|
|
|
25
|
3 |
|
protected function logAlert(string $message, array $context = []): void |
|
26
|
|
|
{ |
|
27
|
3 |
|
$this->log(LogLevel::ALERT, $message, $context); |
|
28
|
3 |
|
} |
|
29
|
|
|
|
|
30
|
3 |
|
protected function logCritical(string $message, array $context = []): void |
|
31
|
|
|
{ |
|
32
|
3 |
|
$this->log(LogLevel::CRITICAL, $message, $context); |
|
33
|
3 |
|
} |
|
34
|
|
|
|
|
35
|
3 |
|
protected function logError(string $message, array $context = []): void |
|
36
|
|
|
{ |
|
37
|
3 |
|
$this->log(LogLevel::ERROR, $message, $context); |
|
38
|
3 |
|
} |
|
39
|
|
|
|
|
40
|
3 |
|
protected function logWarning(string $message, array $context = []): void |
|
41
|
|
|
{ |
|
42
|
3 |
|
$this->log(LogLevel::WARNING, $message, $context); |
|
43
|
3 |
|
} |
|
44
|
|
|
|
|
45
|
3 |
|
protected function logNotice(string $message, array $context = []): void |
|
46
|
|
|
{ |
|
47
|
3 |
|
$this->log(LogLevel::NOTICE, $message, $context); |
|
48
|
3 |
|
} |
|
49
|
|
|
|
|
50
|
3 |
|
protected function logInfo(string $message, array $context = []): void |
|
51
|
|
|
{ |
|
52
|
3 |
|
$this->log(LogLevel::INFO, $message, $context); |
|
53
|
3 |
|
} |
|
54
|
|
|
|
|
55
|
3 |
|
protected function logDebug(string $message, array $context = []): void |
|
56
|
|
|
{ |
|
57
|
3 |
|
$this->log(LogLevel::DEBUG, $message, $context); |
|
58
|
3 |
|
} |
|
59
|
|
|
|
|
60
|
24 |
|
protected function log(string $level, string $message, array $context): void |
|
61
|
|
|
{ |
|
62
|
24 |
|
if ($this->getLogger() instanceof LoggerInterface) { |
|
63
|
24 |
|
$this->getLogger()->log($level, $message, $context); |
|
64
|
|
|
} |
|
65
|
24 |
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|