title: Can the standard Ruby logger be configured to flush after every message?
body: <p>Is it possible for the standard Ruby logger (i.e. <a href="http://rubybrain.com/api/ruby-1.8.7/doc/index.html?a=C00000075&amp;name=Logger" rel="noreferrer"><code>::Logger</code></a>) to auto-flush after each write?</p>
  
  <p><strong>Update:</strong> I am setting a custom log formatter, as per <a href="http://nopugs.com/2008/07/10/how-to-get-timestamps-in-your-ruby-on-rails-logs" rel="noreferrer">How to get timestamps in your ruby on rails logs</a>:</p>
  
  <pre><code>class Foo
    def initialize(params = {})
      @logger = Logger.new $stdout
      @logger.formatter = LogFormatter.new
      @logger.level = params.include?(:log) ? params[:log] : Logger::INFO
      # ...
    end
  
    class LogFormatter &lt; Logger::Formatter
      def call(severity, time, progname, message)
        timestamp = time.iso8601
        log_msg = "#{timestamp}#{" [#{severity}]" if %w{ERROR WARN}.include? severity} "
        if message.is_a? Exception
          log_msg += "#{message.message}"
          log_msg += ": #{message.backtrace.join "\n#{timestamp}  "}" unless message.backtrace.blank?
        else
          log_msg += message
        end
  
        "#{log_msg}\n"
      end
    end
  end
  </code></pre>
  
  <p>I tried to use the suggestion from <a href="https://stackoverflow.com/users/155328/idlefingers">idlefingers</a> as follows:</p>
  
  <pre><code>  def initialize(params = {})
      Rails.logger.auto_flushing = 1
      @logger = Logger.new $stdout
      @logger.formatter = LogFormatter.new
      @logger.level = params.include?(:log) ? params[:log] : Logger::INFO
    end
  </code></pre>
  
  <p>But no dice. Neither does <code>@logger.auto_flushing = 1</code> work for me. What am I doing wrong?</p>
  
  <p><strong>Update:</strong> It turns out that ActiveSupport's <a href="http://www.railsbrain.com/api/rails-2.1.2/doc/index.html?a=C00000047&amp;name=Logger" rel="noreferrer"><code>::Logger</code></a> simply wraps the standard Ruby <code>::Logger</code>. So my question turns out to be about Ruby and not Rails, after all.</p>