diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-01-16 15:52:55 -0800 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-01-16 15:52:55 -0800 |
commit | f5aa4d9a1bc4b77cb5d5fdd970322a80fdac18c6 (patch) | |
tree | 692d495642223ca5a59e71bea09a291ec392cf59 /railties/lib/rails/tasks/log.rake | |
parent | 1a989d473513fd891b1a39f414f9c300a8f7ea63 (diff) | |
parent | 08ac4b967255af6a5d10f36bdec2bf514e5dd500 (diff) | |
download | rails-f5aa4d9a1bc4b77cb5d5fdd970322a80fdac18c6.tar.gz rails-f5aa4d9a1bc4b77cb5d5fdd970322a80fdac18c6.tar.bz2 rails-f5aa4d9a1bc4b77cb5d5fdd970322a80fdac18c6.zip |
Merge pull request #8964 from mattdbridges/specify-log-to-clear
Clear specific logs when using `rake log:clear`
Diffstat (limited to 'railties/lib/rails/tasks/log.rake')
-rw-r--r-- | railties/lib/rails/tasks/log.rake | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/railties/lib/rails/tasks/log.rake b/railties/lib/rails/tasks/log.rake index 6e1334692e..6c3f02eb0c 100644 --- a/railties/lib/rails/tasks/log.rake +++ b/railties/lib/rails/tasks/log.rake @@ -1,9 +1,23 @@ namespace :log do - desc "Truncates all *.log files in log/ to zero bytes" + desc "Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)" task :clear do - FileList["log/*.log"].each do |log_file| - f = File.open(log_file, "w") - f.close + log_files.each do |file| + clear_log_file(file) end end + + def log_files + if ENV['LOGS'] + ENV['LOGS'].split(',') + .map { |file| "log/#{file.strip}.log" } + .select { |file| File.exists?(file) } + else + FileList["log/*.log"] + end + end + + def clear_log_file(file) + f = File.open(file, "w") + f.close + end end |