-
Notifications
You must be signed in to change notification settings - Fork 6
Replace normalizer with message formatter #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ping @Nyholm |
One thing I would like to have in my logs are the response body when the response fails. It often have some detailed error messages. That means I would create a formatter like this: public function formatResponse(ResponseInterface $response)
{
return sprintf(
'%s %s %s with body %s',
$response->getStatusCode(),
$response->getReasonPhrase(),
$response->getProtocolVersion(),
$response->getBody()->__toString()
);
} In my error logs I would get a line like:
I think I would like the response to always be at the end of the log entry. So make the log entry look like this: sprintf('Error: "%s" with when emitting request: "%s". This is the response %s', $exception->getMessage(), $this->formatter->formatRequest($request), $this->formatter->formatResponse($exception->getResponse())), |
You can. There is an interface in the message package which allows you to implement your own formatter. |
Sorry, not done with the post... one sec |
I was too fast on the keys and accidentally posted the comment before I was done writing it. |
+1 With @Nyholm so having response or not does not change the beginning of the message : With response :
Without :
Is that ok with you @Nyholm ? |
14c692a
to
c00bbe7
Compare
Yes, That is what I meant. I think this PR is a great improvement. One could argue that you should be able to configure the complete log entry but I think that is overkill. Good job @sagikazarmark! |
This PR is strictly about replacing Normalizer with formatter, also introduces an interface and possibility to use custom formatters. If you would like to change the log message, please do it in a separate PR/issue. |
Replace normalizer with message formatter
Thanks @Nyholm |
We could always make the write of log entry / errors in decoupled protected function so someone can extend this class and change the message. But yeah another PR. |
I think this is the same case as with the error plugin: it is not that complicated that someone cannot write his/her own. We created the plugin system for this purpose after all. We agree on a common use case and provide that. If someone has different needs, it is not that hard to implement a custom plugin. In HttplugBundle plugin services could even be replace with a custom one. |
No description provided.