1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

clear specific logs when using rake log:clear

This commit is contained in:
Matt Bridges 2013-01-16 12:27:06 -06:00
parent 94384bdbd6
commit 08ac4b9672
3 changed files with 24 additions and 5 deletions

View file

@ -355,7 +355,7 @@ rake assets:clean # Remove compiled assets
rake assets:precompile # Compile all the assets named in config.assets.precompile 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 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 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) rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)

View file

@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ## ## 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 * Allow a `:dirs` key in the `SourceAnnotationExtractor.enumerate` options
to explicitly set the directories to be traversed so it's easier to define to explicitly set the directories to be traversed so it's easier to define
custom rake tasks. custom rake tasks.

View file

@ -1,9 +1,23 @@
namespace :log do 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 task :clear do
FileList["log/*.log"].each do |log_file| log_files.each do |file|
f = File.open(log_file, "w") clear_log_file(file)
f.close
end end
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 end