I have a Rails app, and some custom rake tasks which are called by
cron jobs every hour or so. The rake tasks would just call some
methods on my models to perform some work. The models in turn use
RAILS_DEFAULT_LOGGER.info to emit messages to the log file as needed.
For a good long time everything was working fine, but recently I
noticed that my rake tasks are not resulting in any log file
messages. I know that they are running because the database is
getting get updated as expected.
I then tried to manually run script/console in production mode, and
manually did this:
On Apr 10, 8:43 am, Thorsten M. <rails-mailing-l…@andreas- s.net> wrote:
did you delete an recreate the log file?
you may have messed the file permissions.
Another good suggestion! But file permissions seem to be ok.
The good news is I’ve somehow worked around it by putting this as the
first line in all of my rake tasks:
RAILS_DEFAULT_LOGGER.auto_flushing = true
Now I’m seeing all my output again, yay!
But why should I have to do this? I think (but can’t prove) that this
broke when I upgraded from 1.2.6 to 2.0.2. But if it was a Rails bug,
I would think this would be biting a lot of people, not just me.
Also I’m concerned about the effect this change will have on
performance, so I hope someone can shed some light here.
I just spent hours trying to figure out why my rake task was not
logging in production mode. This has to be a Rails bug. I haven’t
found any tickets on it yet though. The thing about ths is that it
seems to work OK in development mode. Does auto_loading get set to
true somewhere in the development environment? It’s not set in my file
but I don’t know if it gets set somewhere in the bowels of Rails.
“But if it was a Rails bug, I would think this would be biting a lot
of people, not just me.”
Thanks for your post. It took me all day just to find this page. It
took the morning just to figure out that this was the problem. Since I
upgraded to Rail 2.0.2, all “rake db:migrate RAILS_ENV=production”
commands will fail if the migration contains any ActiveRecord commands
(that would normally be logged in development mode) – i.e. commands
like [Model].find(:all), [object].update_attribute(…), etc. No
problem if the migration file contains only regular migration commands
(e.g. add_column, drop_table, etc.).
I tried your suggestion (RAILS_DEFAULT_LOGGER.auto_flushing = true)
but that only made things worse for me. That is, without that command,
the rake command would eventually break and die (MySql lock would time
out). But with this command, rake just hangs there forever.
Why this bug hasn’t been found yet? I suspect it’s a pretty narrow
case involving ActiveRecord, rake, and logger. My situation would seem
common enough to have been found by others. But one can alway work
around elegance to keep the trains moving.
As for me, after 7 hours of banging my head on this obscure issue,
I’ll just go back to a truly awful workaround (i.e. sftp ‘get’ the
production db to my local machine, slurp that data into my local
devlopment db, run the migration locally, sftp ‘put’ the updated db
back up to the server, slurp it in into the production db). Maybe on
another day I’ll do more than browse through the rails code in
bewilderment, and actually find, fix, and publish the bug/fix. But
that day is not today.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.