diff options
author | Matt Bridges <mbridges.91@gmail.com> | 2013-01-16 12:27:06 -0600 |
---|---|---|
committer | Matt Bridges <mbridges.91@gmail.com> | 2013-01-16 17:12:32 -0600 |
commit | 08ac4b967255af6a5d10f36bdec2bf514e5dd500 (patch) | |
tree | 1af5c527b0e9e87ad7c0aa28e951e9e15fb7f702 /railties | |
parent | 94384bdbd6aaf95e57887fa5821018b59ca65037 (diff) | |
download | rails-08ac4b967255af6a5d10f36bdec2bf514e5dd500.tar.gz rails-08ac4b967255af6a5d10f36bdec2bf514e5dd500.tar.bz2 rails-08ac4b967255af6a5d10f36bdec2bf514e5dd500.zip |
clear specific logs when using rake log:clear
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 5 | ||||
-rw-r--r-- | railties/lib/rails/tasks/log.rake | 22 |
2 files changed, 23 insertions, 4 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 4f18f4cdd2..5dbca2e9b4 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* Specify which logs to clear when using the `rake log:clear` task. + (e.g. rake log:clear LOGS=test,staging) + + *Matt Bridges* + * Allow a `:dirs` key in the `SourceAnnotationExtractor.enumerate` options to explicitly set the directories to be traversed so it's easier to define custom rake tasks. 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 |