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
Allow logging request data in the debug log #1089
Allow logging request data in the debug log #1089
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but what about logging what $action
was requested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great
Action? You mean method? It's present in request URL. |
I don't think it's in |
What you mean under "Action"? Example please. |
This information for example helps me to debug MarkdownV2 chars. |
Actually I was worried that sometimes the record with URL can not be just before the data one when bot is heavily used, then I remember you could use Monolog's UidProcessor to know which records were in the same request... |
@jacklul I now understand what you mean!! I've moved the request data output to "just before" the actual response, so if a separate process gets in-between those, all bets are lost anyway 😅 |
So what about log response data too? |
@asafov The HTTP response gets logged just after the (now) request data and the response body itself gets logged in the Or do you mean something more than that? |
I mean this situation for example:
|
If query isn't successfully no any update log will be writed. |
Ah yes, of course! Thought that was in the cURL response 🤦 |
Now you understand what i want? But my PR is incorrect too - it's log all responses, not only errors. Can you fix it? And i think that for errors not need param for log or not, coz it's real error. |
The way it is now, the debug log contains all requests, successful and failed. I think you're right in that only errors should be logged, for So it's probably best to change this behaviour altogether. |
@asafov I've removed bot token you accidentaly posted with the log. You should generate a new one for safety. @noplanman Any chance we could filter out bot tokens from the output ? |
Thanks for removing the key @jacklul. I like the idea of removing the API key from the debug output, but I'm just wondering of a use-case where it might actually help to see it to debug a problem 🤔 Regarding the separate logger, you're suggesting another logger instance on top of the two already set when initialising the logger? |
@jacklul thank you very much. |
@noplanman Actually I just found out you can remove edit revisions too |
…t and add optional switch to also output it for successful requests.
@jacklul Cool, thanks for the info, didn't know that! I've updated this PR to include a variable @asafov Could you have a quick look at this before I merge please? |
I'll PR when I verify it doesn't remove anything else except token, so far I can see it messes up the dates |
Right. It would be nice if we had access to It might need more specific parameters, like |
Actually I'm thinking if we could use second parameter of |
@jacklul You mean like this TelegramLog::debug("Request data:\n{data}", ['data' => print_r($data, true)]);
TelegramLog::debug("Response data:\n{data}", ['data' => $result]); instead of this? TelegramLog::debug('Request data:' . PHP_EOL . print_r($data, true));
TelegramLog::debug('Response data:' . PHP_EOL . $result); Not sure that helps with code readability though. |
No, second argument for methods in PsrLog is context array. TelegramLog::debug('Request data', $data);
TelegramLog::debug('Response data:' . PHP_EOL . $result);
TelegramLog::debug('Response data' , ['result' => $result]);
It actually makes things even worse 😇 I'd say leave it as it is now, if anyone requests it we could implement a switch for this in the future. |
I see, your code takes advantage of Monologs way of converting parameters into strings, in this case converting the This only works for frameworks with such behaviour, which (as far as I know) is not part of the PSR-3 spec. It's kind of "misusing" the context parameters. We'll leave it as it is in that case. |
Summary
Add a new
TelegramLog::$always_log_request_and_response
variable, to output request data to the debug log before posting the request itself to Telegram.