@@ -21,132 +21,132 @@ discard block |
||
21 | 21 | class SeqHandler extends HttpHandler |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * The uri to the logging endpoint of a seq-server. |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - const SEQ_API_URI = 'api/events/raw'; |
|
30 | - |
|
31 | - /** |
|
32 | - * The http method to the logging endpoint of a seq-server. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - const SEQ_API_METHOD = 'POST'; |
|
37 | - |
|
38 | - /** |
|
24 | + /** |
|
25 | + * The uri to the logging endpoint of a seq-server. |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + const SEQ_API_URI = 'api/events/raw'; |
|
30 | + |
|
31 | + /** |
|
32 | + * The http method to the logging endpoint of a seq-server. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + const SEQ_API_METHOD = 'POST'; |
|
37 | + |
|
38 | + /** |
|
39 | 39 | * The options array. |
40 | 40 | * |
41 | 41 | * @var array |
42 | 42 | */ |
43 | 43 | protected $options = [ |
44 | - 'uri' => null, |
|
45 | - 'method' => SeqHandler::SEQ_API_METHOD, |
|
46 | - 'headers' => [ |
|
47 | - 'Content-Type' => 'application/vnd.serilog.clef' |
|
48 | - ], |
|
49 | - 'protocolVersion' => '1.1' |
|
44 | + 'uri' => null, |
|
45 | + 'method' => SeqHandler::SEQ_API_METHOD, |
|
46 | + 'headers' => [ |
|
47 | + 'Content-Type' => 'application/vnd.serilog.clef' |
|
48 | + ], |
|
49 | + 'protocolVersion' => '1.1' |
|
50 | 50 | ]; |
51 | 51 | |
52 | - /** |
|
53 | - * Initializes a new instance of the {@see SeqHandler} class. |
|
54 | - * |
|
55 | - * @param string $serverUri Uri to a seq server instance. |
|
56 | - * @param string|null $apiKey A Seq API key to authenticate or tag messages from the logger. |
|
57 | - * @param int $level The minimum logging level at which this handler will be triggered. |
|
58 | - * @param boolean $bubble Whether the messages that are handled can bubble up the stack or not. |
|
59 | - * @param HttpClient|null $client An instance of a psr-7 http client implementation or null when the |
|
52 | + /** |
|
53 | + * Initializes a new instance of the {@see SeqHandler} class. |
|
54 | + * |
|
55 | + * @param string $serverUri Uri to a seq server instance. |
|
56 | + * @param string|null $apiKey A Seq API key to authenticate or tag messages from the logger. |
|
57 | + * @param int $level The minimum logging level at which this handler will be triggered. |
|
58 | + * @param boolean $bubble Whether the messages that are handled can bubble up the stack or not. |
|
59 | + * @param HttpClient|null $client An instance of a psr-7 http client implementation or null when the |
|
60 | 60 | * HttpClientDiscovery should be used to find an instance. |
61 | - * @param MessageFactory|null $factory An instance of a psr-7 message factory implementation or null when |
|
61 | + * @param MessageFactory|null $factory An instance of a psr-7 message factory implementation or null when |
|
62 | 62 | * the MessageFactoryDiscovery should be used to find an instance. |
63 | - */ |
|
64 | - public function __construct( |
|
65 | - string $serverUri, |
|
66 | - string $apiKey = null, |
|
67 | - $level = Logger::DEBUG, |
|
68 | - $bubble = true, |
|
69 | - HttpClient $client = null, |
|
70 | - MessageFactory $factory = null |
|
71 | - ) { |
|
72 | - $this->setServerUri($serverUri); |
|
73 | - $this->setApiKey($apiKey); |
|
74 | - |
|
75 | - parent::__construct( |
|
76 | - $this->options, |
|
77 | - $client, |
|
78 | - $factory, |
|
79 | - $level, |
|
80 | - $bubble |
|
81 | - ); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Gets the seq server uri. |
|
86 | - * |
|
87 | - * @return string|null |
|
88 | - */ |
|
89 | - public function getServerUri() |
|
90 | - { |
|
91 | - $uri = $this->getUri(); |
|
92 | - |
|
93 | - if (!empty($uri)) { |
|
94 | - return str_replace(SeqHandler::SEQ_API_URI, '', $uri); |
|
95 | - } |
|
96 | - |
|
97 | - return null; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Sets the seq server uri. |
|
102 | - * |
|
103 | - * @param string|null $uri Uri to the seq server instance e.g. 'http://seq-server' or null to disable the |
|
104 | - * {@see SeqHandler}. |
|
105 | - * @return self |
|
106 | - */ |
|
107 | - public function setServerUri(string $uri = null) |
|
108 | - { |
|
109 | - if (!empty($uri)) { |
|
110 | - if (!SeqHandler::endsWith($uri, '/')) { |
|
111 | - $uri = $uri . '/'; |
|
112 | - } |
|
113 | - |
|
114 | - $uri = $uri . SeqHandler::SEQ_API_URI; |
|
115 | - } |
|
116 | - |
|
117 | - $this->setUri($uri); |
|
118 | - |
|
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Gets the Seq API key. |
|
124 | - * |
|
125 | - * @return string|null |
|
126 | - */ |
|
127 | - public function getApiKey() |
|
128 | - { |
|
129 | - return $this->getHeader('X-Seq-ApiKey'); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Sets the Seq API key to authenticate or tag messages from the logger. |
|
134 | - * |
|
135 | - * @param string|null $apiKey The Seq API key or null. |
|
136 | - * @return self |
|
137 | - */ |
|
138 | - public function setApiKey(string $apiKey = null) |
|
139 | - { |
|
140 | - $this->popHeader($apiKey); |
|
141 | - |
|
142 | - if (!empty($apiKey)) { |
|
143 | - $this->pushHeader('X-Seq-ApiKey', $apiKey); |
|
144 | - } |
|
145 | - |
|
146 | - return $this; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
63 | + */ |
|
64 | + public function __construct( |
|
65 | + string $serverUri, |
|
66 | + string $apiKey = null, |
|
67 | + $level = Logger::DEBUG, |
|
68 | + $bubble = true, |
|
69 | + HttpClient $client = null, |
|
70 | + MessageFactory $factory = null |
|
71 | + ) { |
|
72 | + $this->setServerUri($serverUri); |
|
73 | + $this->setApiKey($apiKey); |
|
74 | + |
|
75 | + parent::__construct( |
|
76 | + $this->options, |
|
77 | + $client, |
|
78 | + $factory, |
|
79 | + $level, |
|
80 | + $bubble |
|
81 | + ); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Gets the seq server uri. |
|
86 | + * |
|
87 | + * @return string|null |
|
88 | + */ |
|
89 | + public function getServerUri() |
|
90 | + { |
|
91 | + $uri = $this->getUri(); |
|
92 | + |
|
93 | + if (!empty($uri)) { |
|
94 | + return str_replace(SeqHandler::SEQ_API_URI, '', $uri); |
|
95 | + } |
|
96 | + |
|
97 | + return null; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Sets the seq server uri. |
|
102 | + * |
|
103 | + * @param string|null $uri Uri to the seq server instance e.g. 'http://seq-server' or null to disable the |
|
104 | + * {@see SeqHandler}. |
|
105 | + * @return self |
|
106 | + */ |
|
107 | + public function setServerUri(string $uri = null) |
|
108 | + { |
|
109 | + if (!empty($uri)) { |
|
110 | + if (!SeqHandler::endsWith($uri, '/')) { |
|
111 | + $uri = $uri . '/'; |
|
112 | + } |
|
113 | + |
|
114 | + $uri = $uri . SeqHandler::SEQ_API_URI; |
|
115 | + } |
|
116 | + |
|
117 | + $this->setUri($uri); |
|
118 | + |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Gets the Seq API key. |
|
124 | + * |
|
125 | + * @return string|null |
|
126 | + */ |
|
127 | + public function getApiKey() |
|
128 | + { |
|
129 | + return $this->getHeader('X-Seq-ApiKey'); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Sets the Seq API key to authenticate or tag messages from the logger. |
|
134 | + * |
|
135 | + * @param string|null $apiKey The Seq API key or null. |
|
136 | + * @return self |
|
137 | + */ |
|
138 | + public function setApiKey(string $apiKey = null) |
|
139 | + { |
|
140 | + $this->popHeader($apiKey); |
|
141 | + |
|
142 | + if (!empty($apiKey)) { |
|
143 | + $this->pushHeader('X-Seq-ApiKey', $apiKey); |
|
144 | + } |
|
145 | + |
|
146 | + return $this; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | 150 | * Sets the formatter. |
151 | 151 | * |
152 | 152 | * @param FormatterInterface $formatter The formatter of type SeqBaseFormatter. |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function setFormatter(FormatterInterface $formatter) |
156 | 156 | { |
157 | - if (!($formatter instanceof SeqBaseFormatter)) { |
|
158 | - throw new \InvalidArgumentException('SeqBaseFormatter expected, got ' . gettype($formatter) . ' / ' . get_class($formatter)); |
|
159 | - } |
|
157 | + if (!($formatter instanceof SeqBaseFormatter)) { |
|
158 | + throw new \InvalidArgumentException('SeqBaseFormatter expected, got ' . gettype($formatter) . ' / ' . get_class($formatter)); |
|
159 | + } |
|
160 | 160 | |
161 | 161 | $this->formatter = $formatter; |
162 | 162 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | return $this; |
166 | 166 | } |
167 | 167 | |
168 | - /** |
|
168 | + /** |
|
169 | 169 | * Gets the default formatter. |
170 | 170 | * |
171 | 171 | * @return \Msschl\Monolog\Formatter\SeqCompactJsonFormatter |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | * @return bool |
188 | 188 | */ |
189 | 189 | private static function endsWith(string $haystack, string $needle = null) |
190 | - { |
|
191 | - $length = strlen($needle); |
|
190 | + { |
|
191 | + $length = strlen($needle); |
|
192 | 192 | |
193 | - return $length === 0 || (substr($haystack, -$length) === $needle); |
|
194 | - } |
|
193 | + return $length === 0 || (substr($haystack, -$length) === $needle); |
|
194 | + } |
|
195 | 195 | } |
196 | 196 | \ No newline at end of file |
@@ -108,7 +108,7 @@ |
||
108 | 108 | { |
109 | 109 | if (!empty($uri)) { |
110 | 110 | if (!SeqHandler::endsWith($uri, '/')) { |
111 | - $uri = $uri . '/'; |
|
111 | + $uri = $uri . '/'; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $uri = $uri . SeqHandler::SEQ_API_URI; |
@@ -48,9 +48,9 @@ |
||
48 | 48 | * @param Throwable $e The throwable instance to normalize. |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - protected function normalizeException($e) : string |
|
51 | + protected function normalizeException($e) : string |
|
52 | 52 | { |
53 | - $previousText = ''; |
|
53 | + $previousText = ''; |
|
54 | 54 | if ($previous = $e->getPrevious()) { |
55 | 55 | do { |
56 | 56 | $previousText .= ', ' . get_class($previous) . '(code: ' . $previous->getCode() . '): ' . $previous->getMessage() . ' at ' . $previous->getFile() . ':' . $previous->getLine(); |
@@ -43,13 +43,13 @@ |
||
43 | 43 | * @param bool $extractExtras Flag that indicates whether to extract the context array |
44 | 44 | * to the root or not. |
45 | 45 | */ |
46 | - public function __construct(bool $extractContext = true, bool $extractExtras = true) |
|
47 | - { |
|
46 | + public function __construct(bool $extractContext = true, bool $extractExtras = true) |
|
47 | + { |
|
48 | 48 | $this->extractContext = $extractContext; |
49 | 49 | $this->extractExtras = $extractExtras; |
50 | 50 | |
51 | 51 | parent::__construct(JsonFormatter::BATCH_MODE_NEWLINES); |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Returns a string with the content type for the seq-formatter. |
@@ -14,8 +14,8 @@ |
||
14 | 14 | */ |
15 | 15 | class InvalidCodePathException extends Exception |
16 | 16 | { |
17 | - public function __construct() |
|
18 | - { |
|
19 | - parent::__construct('Invalid code path!'); |
|
20 | - } |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + parent::__construct('Invalid code path!'); |
|
20 | + } |
|
21 | 21 | } |
22 | 22 | \ No newline at end of file |