を実行するrake test
と、毎回エラーラインが表示されます。
log writing failed. "\xE2" from ASCII-8BIT to UTF-8
これをご案内ください。このエラーを取り除く方法。
を実行するrake test
と、毎回エラーラインが表示されます。
log writing failed. "\xE2" from ASCII-8BIT to UTF-8
これをご案内ください。このエラーを取り除く方法。
コードのどこかに、エンコーディングが間違っているか、奇妙な文字が含まれている文字列を出力しようとしていて、エンコーディングが機能しない可能性があります。
正しい方法は、問題が発生する文字列を見つけて、エンコードが間違っている理由を見つけることです。string api( http://ruby-doc.org/core-2.2.0/String.html )のencodingとforce_encodingを参照してください。
その行をログに出力してエラーを回避したいだけの場合は、その文字列を使用して次の手順を実行できます。
str = 'here is some string with wrong encoding and funny characters e.g. "\xE2"'
# note if you do this in console, the str is encoded correctly
# Rails.logger.info(str) # this would result in the error line
# This will change the encoding and remove weird characters
str = str.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_')
Rails.logger.info(str) # this now works
postgresqlを使用していますか?データベースがSQL_ASCIIを使用している可能性があります。psql template1 -c 'show server_encoding'
データベースクラスターの削除を実行し、で再初期化することで、それが正しいかどうかを確認できますinitdb -E utf8 /path/to/database
。
私の場合、いくつかの奇妙な引用符が原因だったので、これらを次のような安全な文字に置き換えました。
msg = error.message.gsub(/[“”]/, "\"").gsub(/[‘’]/,"\'")