HappyDeveloper
HappyDeveloper

Reputation: 12805

Rails logs not working correctly in production

Something is wrong with the logs. They work fine on development, but in production I can't write my own messages.

I haven't changed anything in the configuration files, other than installing Devise and Mongoid. But just in case, I tried uncommenting the line #config.log_level = :debug in production.rb


Controller:

class PagesController < ApplicationController
  def home
    logger.fatal 'bla'
  end

  def about
  end
end


Terminal (log permissions):

root@ubuntu:/srv/www/myapp# ls log -lah
total 496K
drwxr-xr-x  2 myapp root    4.0K 2012-02-21 17:18 .
drwxr-xr-x 14 root  root    4.0K 2012-02-20 14:54 ..
-rw-r--r--  1 myapp myapp    35K 2012-02-21 16:23 development.log
-rw-r--r--  1 myapp root       0 2012-02-17 18:27 .gitkeep
-rw-r--r--  1 root  root    447K 2012-02-21 17:47 passenger.80.log
-rw-r--r--  1 myapp myapp      0 2012-02-21 17:18 production.log


Terminal (passenger):

root@ubuntu:/srv/www/myapp# passenger start -e production -p 80 --user=myapp
=============== Phusion Passenger Standalone web server started ===============
PID file: /srv/www/myapp/tmp/pids/passenger.80.pid
Log file: /srv/www/myapp/log/passenger.80.log
Environment: production
Accessible via: http://0.0.0.0/

You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================================
cache: [HEAD /] miss
cache: [GET /] miss

Upvotes: 2

Views: 3352

Answers (1)

Dylan Markow
Dylan Markow

Reputation: 124419

Assuming you're on Rails 3.2.0 or Rails 3.2.1, this is a known issue (see https://github.com/rails/rails/issues/4277). It's already been fixed, but hasn't been released yet.

A workaround is to add an initializer with:

Rails.logger.instance_variable_get(:@logger).instance_variable_get(:@log_dest).sync = true if Rails.logger

Update: Rails 3.2.2 fixes this.

Upvotes: 5

Related Questions