Skip to content
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

Fix log crashing on encoded str other than utf8 #1001

Closed
wants to merge 1 commit into from

Conversation

sametmax
Copy link

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:

import logging
logging.getLogger('aioftp.client').setLevel(logging.ERROR)

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 "?".

@codecov-io
Copy link

codecov-io commented Mar 25, 2017

Codecov Report

Merging #1001 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1001   +/-   ##
=======================================
  Coverage   52.95%   52.95%           
=======================================
  Files         110      110           
  Lines       14721    14721           
  Branches     2191     2191           
=======================================
  Hits         7796     7796           
  Misses       6502     6502           
  Partials      423      423
Impacted Files Coverage Δ
crossbar/controller/processtypes.py 30.89% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fff810a...32fa0f0. Read the comment docs.

@oberstet
Copy link
Contributor

This is bad, I agree. I also agree that logging has to cope with bytes in general (we cannot change all things that might log bytes raw). However, this should be fixed once and for all, at the logging system, and that means within txaio.

Hence, I am closing this one and migrate the issue to txaio: crossbario/txaio#93

@oberstet oberstet closed this Mar 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants