|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @codingStandardsIgnoreStart |
|
4
|
|
|
* |
|
5
|
|
|
* @author Barney Hanlon <[email protected]> |
|
6
|
|
|
* @copyright Barney Hanlon 2017 |
|
7
|
|
|
* @license https://opensource.org/licenses/MIT |
|
8
|
|
|
* |
|
9
|
|
|
* @codingStandardsIgnoreEnd |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Shrikeh\GuzzleMiddleware\TimerLogger\Formatter; |
|
13
|
|
|
|
|
14
|
|
|
use Psr\Http\Message\RequestInterface; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
use Psr\Log\LogLevel; |
|
17
|
|
|
use Shrikeh\GuzzleMiddleware\TimerLogger\Formatter\Message\DefaultStartMessage; |
|
18
|
|
|
use Shrikeh\GuzzleMiddleware\TimerLogger\Formatter\Message\DefaultStopMessage; |
|
19
|
|
|
use Shrikeh\GuzzleMiddleware\TimerLogger\Timer\TimerInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Verbose. |
|
23
|
|
|
*/ |
|
24
|
|
|
class Verbose implements FormatterInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var RequestStartInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $start; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var RequestStopInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
private $stop; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $startLevel The level of logging for start messages |
|
38
|
|
|
* @param string $stopLevel The level of logging for stop messages |
|
39
|
|
|
* |
|
40
|
|
|
* @return self |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function quickStart( |
|
43
|
|
|
$startLevel = LogLevel::DEBUG, |
|
44
|
|
|
$stopLevel = LogLevel::DEBUG |
|
45
|
|
|
) { |
|
46
|
|
|
return self::fromCallables( |
|
47
|
|
|
new DefaultStartMessage(), |
|
48
|
|
|
new DefaultStopMessage(), |
|
49
|
|
|
$startLevel, |
|
50
|
|
|
$stopLevel |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param callable $start A callable to use for formatting start messages |
|
56
|
|
|
* @param callable $stop A callable to use for formatting stop messages |
|
57
|
|
|
* @param string $startLevel The level for start messages |
|
58
|
|
|
* @param string $stopLevel The level for stop messages |
|
59
|
|
|
* |
|
60
|
|
|
* @return self |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function fromCallables( |
|
63
|
|
|
callable $start, |
|
64
|
|
|
callable $stop, |
|
65
|
|
|
$startLevel = LogLevel::DEBUG, |
|
66
|
|
|
$stopLevel = LogLevel::DEBUG |
|
67
|
|
|
) { |
|
68
|
|
|
return new self( |
|
69
|
|
|
new StartFormatter($start, $startLevel), |
|
70
|
|
|
new StopFormatter($stop, $stopLevel) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Verbose constructor. |
|
76
|
|
|
* |
|
77
|
|
|
* @param RequestStartInterface $start A formatter for when the Request starts |
|
78
|
|
|
* @param RequestStopInterface $stop A formatter for when the Request ends |
|
79
|
|
|
*/ |
|
80
|
|
|
public function __construct( |
|
81
|
|
|
RequestStartInterface $start, |
|
82
|
|
|
RequestStopInterface $stop |
|
83
|
|
|
) { |
|
84
|
|
|
$this->start = $start; |
|
85
|
|
|
$this->stop = $stop; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* {@inheritdoc} |
|
90
|
|
|
*/ |
|
91
|
|
|
public function levelStart(TimerInterface $timer, RequestInterface $request) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->start->levelStart($timer, $request); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritdoc} |
|
98
|
|
|
*/ |
|
99
|
|
|
public function start(TimerInterface $timer, RequestInterface $request) |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->start->start($timer, $request); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritdoc} |
|
106
|
|
|
*/ |
|
107
|
|
|
public function levelStop( |
|
108
|
|
|
TimerInterface $timer, |
|
109
|
|
|
RequestInterface $request, |
|
110
|
|
|
ResponseInterface $response |
|
111
|
|
|
) { |
|
112
|
|
|
return $this->stop->levelStop($timer, $request, $response); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* {@inheritdoc} |
|
117
|
|
|
*/ |
|
118
|
|
|
public function stop( |
|
119
|
|
|
TimerInterface $timer, |
|
120
|
|
|
RequestInterface $request, |
|
121
|
|
|
ResponseInterface $response |
|
122
|
|
|
) { |
|
123
|
|
|
return $this->stop->stop($timer, $request, $response); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|