Skip to content

Commit 85dc4e3

Browse files
committed
feature #12594 [DX] [HttpKernel] Use "context" argument when logging route in RouterListener (iltar)
This PR was merged into the 2.7 branch. Discussion ---------- [DX] [HttpKernel] Use "context" argument when logging route in RouterListener | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT When using the "fingers_crossed" option, I only log stuff when a certain level is reached. I found the matched route with parameters to be extremely useful. The only problem was, that it gets dumped in a string, which reduces readability significantly when having multiple parameters. I've used the context argument to provide the additional information so it becomes easier to read. Especially for formatters that use the context, such as the HtmlFormatter, can really use this. *I've done a quick check and noticed that almost always the information is dumped in the message, while I think it should be in the context. Is this something that should be changed in general?* Commits ------- 448c03f [HttpKernel] RouterListener uses "context" argument when logging route
2 parents 7f6533f + f9b33e6 commit 85dc4e3

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

EventListener/RouterListener.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function onKernelRequest(GetResponseEvent $event)
128128
}
129129

130130
if (null !== $this->logger) {
131-
$this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters)));
131+
$this->logger->info(sprintf('Matched route "%s"', $parameters['_route']), $parameters);
132132
}
133133

134134
$request->attributes->add($parameters);
@@ -150,16 +150,6 @@ public function onKernelRequest(GetResponseEvent $event)
150150
}
151151
}
152152

153-
private function parametersToString(array $parameters)
154-
{
155-
$pieces = array();
156-
foreach ($parameters as $key => $val) {
157-
$pieces[] = sprintf('"%s": "%s"', $key, (is_string($val) ? $val : json_encode($val)));
158-
}
159-
160-
return implode(', ', $pieces);
161-
}
162-
163153
public static function getSubscribedEvents()
164154
{
165155
return array(

0 commit comments

Comments
 (0)