Skip to content

Instantly share code, notes, and snippets.

@jasonrudolph
Created May 5, 2011 00:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonrudolph/956295 to your computer and use it in GitHub Desktop.
Save jasonrudolph/956295 to your computer and use it in GitHub Desktop.
Rake tasks fail to log when running in production mode
# generate a fresh app
rails -v
rails new whizbang
cd whizbang
# show empty log file
cat log/production.log
# script/runner successfully writes to the log file
./script/rails runner 'Rails.logger.error("Hello from script/runner")' -e production
cat log/production.log
# rake tasks don't write to the log file
vim lib/tasks/logging.rake
cat lib/tasks/logging.rake
cat /dev/null > log/production.log
cat log/production.log
RAILS_ENV=production rake logging:example
cat log/production.log
namespace :logging do
task :example => [:environment] do
Rails.logger.error("Hello from rake")
end
end
[tmp] # generate a fresh app
[tmp] rails -v
Rails 3.0.7
[tmp] rails new whizbang
create
create README
create Rakefile
...
[tmp] cd whizbang
/tmp/whizbang
[whizbang]
[whizbang] # show empty log file
[whizbang] cat log/production.log
[whizbang]
[whizbang] # script/runner successfully writes to the log file
[whizbang] ./script/rails runner 'Rails.logger.error("Hello from script/runner")' -e production
[whizbang] cat log/production.log
Hello from script/runner
[whizbang]
[whizbang] # rake tasks don't write to the log file
[whizbang] vim lib/tasks/logging.rake
[whizbang] cat lib/tasks/logging.rake
namespace :logging do
task :example => [:environment] do
Rails.logger.error("Hello from rake")
end
end
[whizbang] cat /dev/null > log/production.log
[whizbang] cat log/production.log
[whizbang] RAILS_ENV=production rake logging:example
(in /private/tmp/whizbang)
[whizbang] cat log/production.log
[whizbang]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment