Created
May 5, 2011 00:16
-
-
Save jasonrudolph/956295 to your computer and use it in GitHub Desktop.
Rake tasks fail to log when running in production mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :logging do | |
task :example => [:environment] do | |
Rails.logger.error("Hello from rake") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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