1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Queue; |
4
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
6
|
|
|
use Symbiote\QueuedJobs\Services\QueuedJob; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Logger |
10
|
|
|
* |
11
|
|
|
* This logger redirects all log messages to the queued job which makes the job data contain all relevant logs |
12
|
|
|
* |
13
|
|
|
* @package App\Queue |
14
|
|
|
*/ |
15
|
|
|
class Logger implements LoggerInterface |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var QueuedJob|null |
20
|
|
|
*/ |
21
|
|
|
private $job = null; |
22
|
|
|
|
23
|
|
|
public function setJob(?QueuedJob $job): void |
24
|
|
|
{ |
25
|
|
|
$this->job = $job; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function debug($message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
29
|
|
|
{ |
30
|
|
|
$this->logJobMessage($message); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function critical($message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
34
|
|
|
{ |
35
|
|
|
$this->logJobMessage($message); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function alert($message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
39
|
|
|
{ |
40
|
|
|
$this->logJobMessage($message); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function log($level, $message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
44
|
|
|
{ |
45
|
|
|
$this->logJobMessage($message); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function emergency($message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
49
|
|
|
{ |
50
|
|
|
$this->logJobMessage($message); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function warning($message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
54
|
|
|
{ |
55
|
|
|
$this->logJobMessage($message); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function error($message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
59
|
|
|
{ |
60
|
|
|
$this->logJobMessage($message); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function notice($message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
64
|
|
|
{ |
65
|
|
|
$this->logJobMessage($message); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function info($message, array $context = []): void // phpcs:ignore SlevomatCodingStandard.TypeHints |
69
|
|
|
{ |
70
|
|
|
$this->logJobMessage($message); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function logJobMessage(string $message): void |
74
|
|
|
{ |
75
|
|
|
$job = $this->job; |
76
|
|
|
|
77
|
|
|
if (!$job instanceof QueuedJob) { |
78
|
|
|
return; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$job->addMessage($message); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|