Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker
Herval Freire

[NY] Standup 1/25

Herval Freire
Friday, January 25, 2013

Interestings

Beware of absolute paths when using unicorn and USR2

Using unicorns USR2 signal to restart does NOT re-read your unicorn config so be very careful with Capistrano deployments. See SO Q&A for details below:

http://stackoverflow.com/questions/9388074/restarting-unicorn-with-usr2-doesnt-seem-to-reload-production-rb-settings

Additionally you should specify several things in the config file, specifically the gemfile, or it won’t reload that either.
APP_ROOT = DIR
ENV['BUNDLE_GEMFILE'] = DIR/Gemfile

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Ryan Ong

How to split up rails 3.x logger by unicorn workers

Ryan Ong
Friday, January 11, 2013

TLDR: Put this in your unicorn config. Make sure not to have duplicate after_fork calls

after_fork do |server, worker|
  if defined?(ActiveSupport::TaggedLogging) && Rails.logger.kind_of?(ActiveSupport::TaggedLogging)
    Rails.logger.instance_eval do
      level = @logger.level
      # flush and close logger to make sure we don't cut off any potential logging before this
      @logger && @logger.flush && @logger.close
      @logger = ActiveSupport::BufferedLogger.new(Rails.root.join("log", "rails_#{Rails.env}.#{worker.nr}.log").to_s, level)
    end
  elsif Rails.logger.kind_of?(ActiveSupport::BufferedLogger)
    Rails.logger.instance_eval do
      @log && @log.flush && @log.close
      @log_path = Rails.root.join("log", "rails_#{Rails.env}.#{worker.nr}.log").to_s
      if respond_to?(:open_logfile, true)
        @log = open_logfile(@log_path)
      elsif respond_to?(:open_log, true)
        if File.exist?(@log_path)
          @log = open_log(@log_path, (File::WRONLY | File::APPEND))
        else
          FileUtils.mkdir_p(File.dirname(@log_path))
          @log = open_log(l@log_path, (File::WRONLY | File::APPEND | File::CREAT))
        end
      end
    end
  end
end

How this works!

There is no easy way to change the path of a log or swap out the logger. When rails is instantiated ActionController and ActiveRecord assigns their local logger from Rails.logger. So if you reassign Rails.logger to a new one ActionController and ActiveRecord will continue to use the old rails logger.

There are no methods to change or swap out the log path in the Logging class. In order to change the log path we have to change instance variables to either a new logger or a new file handler.

In Rails 3.2 ActiveSupport::TaggedLogging was added!
If you look here you can see how Rails.logger is assigned! (source)
As you can see TaggedLogging basically just wraps a buffered logger. So when we open up Rails.logger we can patch what TaggedLogging wraps by modifying the @logger variable.
If TaggedLogging isn’t used we can use the open_logfile command and just insert a path.

In Rails 3.0 and Rails 3.1 TaggedLogging isn’t used and by default uses BufferedLogger.
We have to create a new file handler using the open_log method and reassign the @log variable.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 9/9/2009: Unicorn, Thin, and Mongrel

Pivotal Labs
Wednesday, September 9, 2009

Ask for Help

“Has anyone used Unicorn“

No one present is using Unicorn. Some wondered how it differs from Thin.

This raised the question:

“Is there a road map for mongrel and rails? Mongrel uses CGI and Rails 2.3 has removed CGI.”

In the Ruby on Rails 2.3 Release Notes, there is the statement

…but if you use CGI, don’t worry; Rails now supports CGI
through a proxy interface…

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (780)
  • rails (113)
  • testing (88)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (55)
  • techtalk (44)
  • rspec (38)
  • ironblogger (32)
  • productivity (30)
  • activerecord (29)
  • gogaruco (29)
  • git (28)
  • nyc (27)
  • rubymine (26)
  • bloggerdome (23)
  • mobile (22)
  • process (21)
  • pivotal tracker (20)
  • cucumber (20)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • css (13)
  • tdd (13)
  • selenium (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to unicorn Feed
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >