2006-02-28 17:40:19 -05:00
|
|
|
namespace :log do
|
2013-01-16 13:27:06 -05:00
|
|
|
desc "Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)"
|
2006-02-28 11:28:11 -05:00
|
|
|
task :clear do
|
2013-01-16 13:27:06 -05:00
|
|
|
log_files.each do |file|
|
|
|
|
clear_log_file(file)
|
2006-02-28 11:28:11 -05:00
|
|
|
end
|
|
|
|
end
|
2013-01-16 13:27:06 -05:00
|
|
|
|
|
|
|
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
|
2006-02-28 11:28:11 -05:00
|
|
|
end
|