1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kaliop\eZObjectWrapperBundle\Core\Traits; |
4
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Adds the capability to log. |
9
|
|
|
* |
10
|
|
|
* Does not use the magic method __call, as traits do not allow to overload it more than once at a time, so usage would |
11
|
|
|
* be awkward at best. |
12
|
|
|
*/ |
13
|
|
|
trait LoggingEntity |
14
|
|
|
{ |
15
|
|
|
private $logger; |
16
|
|
|
|
17
|
|
|
protected function setLogger(LoggerInterface $logger = null) |
18
|
|
|
{ |
19
|
|
|
$this->logger = $logger; |
20
|
|
|
return $this; // fluent interfaces for setters |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function emergency($message, array $context = array()) |
24
|
|
|
{ |
25
|
|
|
if ($this->logger) $this->logger->emergency($message, $context); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function alert($message, array $context = array()) |
29
|
|
|
{ |
30
|
|
|
if ($this->logger) $this->logger->alert($message, $context); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function critical($message, array $context = array()) |
34
|
|
|
{ |
35
|
|
|
if ($this->logger) $this->logger->critical($message, $context); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function error($message, array $context = array()) |
39
|
|
|
{ |
40
|
|
|
if ($this->logger) $this->logger->error($message, $context); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function warning($message, array $context = array()) |
44
|
|
|
{ |
45
|
|
|
if ($this->logger) $this->logger->warning($message, $context); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function notice($message, array $context = array()) |
49
|
|
|
{ |
50
|
|
|
if ($this->logger) $this->logger->notice($message, $context); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function info($message, array $context = array()) |
54
|
|
|
{ |
55
|
|
|
if ($this->logger) $this->logger->info($message, $context); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function debug($message, array $context = array()) |
59
|
|
|
{ |
60
|
|
|
if ($this->logger) $this->logger->debug($message, $context); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function log($level, $message, array $context = array()) |
64
|
|
|
{ |
65
|
|
|
if ($this->logger) $this->logger->log($level, $message, $context); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|