Skip to content

Instantly share code, notes, and snippets.

@jwcastillo
Forked from jasonrudolph/how-to-reproduce.sh
Created October 2, 2016 23:30
Show Gist options
  • Save jwcastillo/9ecdc3e5a9f0682b21a4b35d542a3fd6 to your computer and use it in GitHub Desktop.
Save jwcastillo/9ecdc3e5a9f0682b21a4b35d542a3fd6 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