Completed
Pull Request — master (#7)
by Ross
04:00
created

ClassNameFormatter::logCommandReceived()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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($commandReceivedLevel = LogLevel::DEBUG, $commandSucceededLevel = LogLevel::DEBUG, $commandFailedLevel = LogLevel::ERROR)
34
    {
35
        $this->commandReceivedLevel = $commandReceivedLevel;
36
        $this->commandSucceededLevel = $commandSucceededLevel;
37
        $this->commandFailedLevel = $commandFailedLevel;
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function logCommandReceived(LoggerInterface $logger, $command)
44
    {
45
        $logger->log($this->commandReceivedLevel, 'Command received: ' . get_class($command), []);
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function logCommandSucceeded(LoggerInterface $logger, $command, $returnValue)
52
    {
53
        $logger->log($this->commandSucceededLevel, 'Command succeeded: ' . get_class($command), []);
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59
    public function logCommandFailed(LoggerInterface $logger, $command, Exception $e)
60
    {
61
        $logger->log(
62
            $this->commandFailedLevel,
63
            'Command failed: ' . get_class($command),
64
            ['exception' => $e]
65
        );
66
    }
67
}
68