Fix log crashing on encoded str other than utf8 #1001
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I recently used crossbar with aioftp. This lib logs by default everything sent from the ftp server, directly as bytes, and crashed my crossbar instance which assumes any byte strings is UTF8 encoded.
The workaround was for me to simply tune down aioftp verbose logging with something like:
But it could have been useful information that I didn't want to loose in the log. Plus I doubt aioftp is the only lib that will do something like that, and we can't chase them all. What's more, it requires some skills to track down this problem, and the workaround won't seem obvious for most users, which will probably end up opening a ticket here.
It's a difficult problem because passing bytes to the logger are not only bad practice, but very hard to mitigate, as there is no way to pass get the bytes charset.
I'm offering this solution, which is the lesser of all evils : if some third party misbehave and log non ascii bytes, and since would be painful to do anything else than trying to decode as UTF8, I use errors="replace". This instruct the decoder to simply replace anything it can't decode by a "?".