Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Jan 3, 2015
2 parents 8e6b0bb + 448c03f commit 193d69c
Showing 1 changed file with 1 addition and 11 deletions.
Expand Up @@ -128,7 +128,7 @@ public function onKernelRequest(GetResponseEvent $event)
}

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

$request->attributes->add($parameters);
Expand All @@ -150,16 +150,6 @@ public function onKernelRequest(GetResponseEvent $event)
}
}

private function parametersToString(array $parameters)
{
$pieces = array();
foreach ($parameters as $key => $val) {
$pieces[] = sprintf('"%s": "%s"', $key, (is_string($val) ? $val : json_encode($val)));
}

return implode(', ', $pieces);
}

public static function getSubscribedEvents()
{
return array(
Expand Down

0 comments on commit 193d69c

Please sign in to comment.