-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Attempt UTF-8 encoding in logger formatter #6937
Conversation
While running specs with Capybara and Selenium I've been experiencing a stream of `log writing failed. "\xC2" from ASCII-8BIT to UTF-8` errors; not sure of all the context, but adding this encoding to the formatter seems to be a fix.
Oh, this is weird. Is it possible for you to narrow down your test to understand where this message gets broken? I think it would be great to understand what the particular issue is. I think your changes make sense, but they are impossible in pure Ruby - there is no |
@@ -122,7 +122,7 @@ def create_logger(output) | |||
logger.progname = 'Selenium' | |||
logger.level = default_level | |||
logger.formatter = proc do |severity, time, progname, msg| | |||
"#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n" | |||
"#{time.strftime('%F %T')} #{severity} #{progname} #{msg.try(:force_encoding, 'UTF-8')}\n" |
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.
I've been working in this area (Encoding), a lot recently. Can you try the following code.
def utf8?
Encoding.default_internal == Encoding::UTF_8 &&
Encoding.default_external == Encoding::UTF_8
end
# Then in your block
msg = msg.force_encoding('UTF-8') if msg.respond_to?(:force_encoding)
Now to the caveats. ASCII-8BIT is a useful encoding char-set because it allows things like german umlauts and other stuff. I actually have the following code in my new API tests I write
# file - env.rb
# Set these to 8bit to allow umlauts
Encoding.default_external = Encoding::ASCII_8BIT
Encoding.default_internal = Encoding::ASCII_8BIT
What is your current Encoding.default_external / internal
values, could it be your system is somehow setting up some weird ones?
I've been trying to reproduce the issue by sending non-ASCII-8bit characters to it, but they are parsed perfectly fine, so I'm not sure if this issue is still present in the recent version of selenium-webdriver. Since there was no response for a few months, I'm closing this PR. I'll be happy to continue the conversation and re-open if somebody replies. |
This is an old issue but I believe the problem described here is still present. For me it happens when setting
This happens even when |
If you google for this problem there are tons of unrelated projects that have had the same issue (cf. elastic/elasticsearch-ruby#71), so it was difficult for me to localize the issue to Selenium in my case. But using |
Hi @codyrobbins - I have a small gem that will patch this and remove this problem To use it simply do
The issue I found was actually further down to the issues in RubyMine and that the issues in Ruby 3.2+ are now localised to just rubymine |
This should solve warnings from #6937
This should solve warnings from SeleniumHQ#6937
While running specs with Capybara and Selenium I've been experiencing a stream of
log writing failed. "\xC2" from ASCII-8BIT to UTF-8
errors; not sure of all the context, but adding this encoding to the formatter seems to be a fix--any reason not to add this to the formatter?X
in the preceding checkbox, I verify that I have signed the Contributor License AgreementThis change is