|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nopolabs\Yabot\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Psr\Log\LoggerInterface; |
|
7
|
|
|
use Psr\Log\NullLogger; |
|
8
|
|
|
|
|
9
|
|
|
trait LogTrait |
|
10
|
|
|
{ |
|
11
|
|
|
private $log; |
|
12
|
|
|
|
|
13
|
|
|
protected function setLog(LoggerInterface $log = null) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->log = $log ?? new NullLogger(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
protected function getLog() : LoggerInterface |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->log; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function emergency($message, array $context = array()) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->getLog()->emergency($message, $context); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
protected function alert($message, array $context = array()) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->getLog()->alert($message, $context); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function critical($message, array $context = array()) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->getLog()->critical($message, $context); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function error($message, array $context = array()) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->getLog()->error($message, $context); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function warning($message, array $context = array()) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->getLog()->warning($message, $context); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function notice($message, array $context = array()) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->getLog()->notice($message, $context); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function info($message, array $context = array()) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->getLog()->info($message, $context); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function debug($message, array $context = array()) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->getLog()->debug($message, $context); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
protected function log($level, $message, array $context = array()) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->getLog()->log($level, $message, $context); |
|
66
|
|
|
} |
|
67
|
|
|
} |