diff --git a/guides/source/command_line.md b/guides/source/command_line.md index 12d39ea1cc546be8d6c82e7022a8fee632ce5eb9..0081e6427e3bcefc67b0ae638b375c05d8937833 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -355,7 +355,7 @@ rake assets:clean # Remove compiled assets rake assets:precompile # Compile all the assets named in config.assets.precompile rake db:create # Create the database from config/database.yml for the current Rails.env ... -rake log:clear # Truncates all *.log files in log/ to zero bytes +rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development) rake middleware # Prints out your Rack middleware stack ... rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear) diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 4f18f4cdd29b92b3192d69eff4ac28d0e0cb78ae..5dbca2e9b44939f9a0c54f9852748f54ae8ca6ad 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 6e1334692ee2bdfbb65eaa26a84ebc359ccde790..6c3f02eb0cbfb9a2ef56e67a7cd9ffbef86e3cc8 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