This project is archived and is in readonly mode.

#3836 ✓stale

ruby 1.9 buffered logger -> encoding errors

Reported by Paul | February 1st, 2010 @ 05:26 PM

i am in the process of migrating to ruby1.9 and i had serious trouble with encoding and the buffered logger.

Assume you are logging sql utf-8 content and logging a request uri with iso parts in it.

i ended up with

@log = open(log, "a:ASCII-8BIT")


buffer << message.force_encoding('ASCII-8BIT')

as the sources for logging messages are - with respect to encoding - not under my control.

... or do i miss something very simple in here ??

Comments and changes to this ticket

  • Ivan Ukhov

    Ivan Ukhov April 12th, 2010 @ 12:40 AM

    I have the same problem, when SQL query contains UTF-8 characters, so my patch looks like this:

    module ActiveSupport
      class BufferedLogger
        def add(severity, message = nil, progname = nil, &block)
          return if @level > severity
          message = (message || (block && || progname).to_s
          # If a newline is necessary then create a new message ending with a newline.
          # Ensures that the original message is not mutated.
          message = "#{message}\n" unless message[-1] == ?\n
          buffer << message.force_encoding('utf-8')
  • majki

    majki April 16th, 2010 @ 09:07 AM

    I made the same patch in my app. However to make it a bit prettier I used Encoding.default_external instead of hardcoding utf-8

  • majki

    majki April 16th, 2010 @ 09:07 AM

    • Tag changed from 2.3.6, encoding, ruby19 to 2.3.6, 3.0pre, encoding, ruby19
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:43 PM

    • State changed from “new” to “open”
    • Tag changed from 2.3.6, 3.0pre, encoding, ruby19 to 236, 30pre, encoding, ruby19

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:43 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket

Referenced by