1
|
|
|
<?php |
2
|
|
|
namespace League\Tactician\Logger\Formatter; |
3
|
|
|
|
4
|
|
|
use Exception; |
5
|
|
|
use Psr\Log\LoggerInterface; |
6
|
|
|
use Psr\Log\LogLevel; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Returns log messages only dump the Command & Exception's class names. |
10
|
|
|
*/ |
11
|
|
|
class ClassNameFormatter implements Formatter |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $commandReceivedLevel; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $commandSucceededLevel; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $commandFailedLevel; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $commandReceivedLevel |
30
|
|
|
* @param string $commandSucceededLevel |
31
|
|
|
* @param string $commandFailedLevel |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
$commandReceivedLevel = LogLevel::DEBUG, |
35
|
|
|
$commandSucceededLevel = LogLevel::DEBUG, |
36
|
|
|
$commandFailedLevel = LogLevel::ERROR |
37
|
|
|
) { |
38
|
|
|
$this->commandReceivedLevel = $commandReceivedLevel; |
39
|
|
|
$this->commandSucceededLevel = $commandSucceededLevel; |
40
|
|
|
$this->commandFailedLevel = $commandFailedLevel; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritDoc} |
45
|
|
|
*/ |
46
|
|
|
public function logCommandReceived(LoggerInterface $logger, $command) |
47
|
|
|
{ |
48
|
|
|
$logger->log($this->commandReceivedLevel, 'Command received: ' . get_class($command), []); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritDoc} |
53
|
|
|
*/ |
54
|
|
|
public function logCommandSucceeded(LoggerInterface $logger, $command, $returnValue) |
55
|
|
|
{ |
56
|
|
|
$logger->log($this->commandSucceededLevel, 'Command succeeded: ' . get_class($command), []); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
*/ |
62
|
|
|
public function logCommandFailed(LoggerInterface $logger, $command, Exception $e) |
63
|
|
|
{ |
64
|
|
|
$logger->log( |
65
|
|
|
$this->commandFailedLevel, |
66
|
|
|
'Command failed: ' . get_class($command), |
67
|
|
|
['exception' => $e] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|