aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2016-01-09 18:02:28 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2016-01-09 18:02:28 +0100
commit9d681fc74c6251d5f2b93fa9576c9b2113116680 (patch)
tree493c4418cac398fc58c214a42e15e47e5d147e25 /railties/lib
parent2ac430f4f9778d01f5067f523578d7a6744ab220 (diff)
parent68f46a815fc30e9de0065c1726f18f4c916bb776 (diff)
downloadrails-9d681fc74c6251d5f2b93fa9576c9b2113116680.tar.gz
rails-9d681fc74c6251d5f2b93fa9576c9b2113116680.tar.bz2
rails-9d681fc74c6251d5f2b93fa9576c9b2113116680.zip
Merge pull request #22703 from joshsoftware/rake-log-clear
rake log:clear task updated
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/tasks/log.rake25
1 files changed, 19 insertions, 6 deletions
diff --git a/railties/lib/rails/tasks/log.rake b/railties/lib/rails/tasks/log.rake
index 877f175ef3..073f235ec5 100644
--- a/railties/lib/rails/tasks/log.rake
+++ b/railties/lib/rails/tasks/log.rake
@@ -1,5 +1,12 @@
namespace :log do
- desc "Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)"
+
+ ##
+ # Truncates all/specified log files
+ # ENV['LOGS']
+ # - defaults to standard environment log files i.e. 'development,test,production'
+ # - ENV['LOGS']=all truncates all files i.e. log/*.log
+ # - ENV['LOGS']='test,development' truncates only specified files
+ desc "Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)"
task :clear do
log_files.each do |file|
clear_log_file(file)
@@ -7,15 +14,21 @@ namespace :log do
end
def log_files
- if ENV['LOGS']
- ENV['LOGS'].split(',')
- .map { |file| "log/#{file.strip}.log" }
- .select { |file| File.exist?(file) }
- else
+ if ENV['LOGS'] == 'all'
FileList["log/*.log"]
+ elsif ENV['LOGS']
+ log_files_to_truncate(ENV['LOGS'])
+ else
+ log_files_to_truncate("development,test,production")
end
end
+ def log_files_to_truncate(envs)
+ envs.split(',')
+ .map { |file| "log/#{file.strip}.log" }
+ .select { |file| File.exist?(file) }
+ end
+
def clear_log_file(file)
f = File.open(file, "w")
f.close