Monday, 5 April 2010

Rails, flushing buffer log - what a waste of time to fix it

It was so stupid...

There was a ruby on rails application. There were some changes in a production server. Some missing libraries needed to be added. You are fixing one thing then another, try and fix, try and fix and so on. That is fine as long as we know what needs to be done.

Finally this application was ready to work in development but not in production mode. There was nothing on screen nor in log/development.log even with enabled -u (debug) flag for script/server (you should have ruby-debug gem and ruby-dev package also as a dependency).

What is wrong as I am still getting "Application error
There is an error in this application. Please let us apologize for this inconvenience and help to fix it by reporting this problem to site-master", why there is NOTHING in the log or maybe - where is this f..$%&* log at all? log/production.log is untouched even after shutting down the server.

Ok, probably the error is somewhere in differences between environments so maybe this could be a database.yml, different place of connection socket but why I can not see even a simple error message about this?

After some time for browsing forums, groups and so on the proper solution was to add
Rails.logger.auto_flushing = 1
at the end of my config/environment.rb

My question is - even if this large buffer is understandable solution for heavy production environments why I cannot see anything after closing down my server? Should not this log be flushed then?

If you want to check your logger settings...

Run your rails console:


and then type:

so it looks like:
script/console production
Loading production environment (Rails 2.3.5)

and check @auto_flushing= value.

If you have @auto_flushing=1 then you are at home.