Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ruby 1.9 buffered logger -> encoding errors

#3836

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")

and

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

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Ivan Ukhov
    Ivan Ukhov

    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 && block.call) || 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')
          auto_flush
          message
        end
      end
    end
    

    April 12th, 2010 @ 12:40 AM

  2. majki
    majki

    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

    April 16th, 2010 @ 09:07 AM

  3. majki
    majki
    • Tag changed from 2.3.6, encoding, ruby19 to 2.3.6, 3.0pre, encoding, ruby19

    April 16th, 2010 @ 09:07 AM

  4. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:43 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:43 PM