1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/tasks/log.rake
Ryuta Kamizono 6f58b2cfc9 Enable Layout/EmptyLinesAroundBlockBody to reduce review cost in the future
We sometimes ask "✂️ extra blank lines" to a contributor in reviews like
https://github.com/rails/rails/pull/33337#discussion_r201509738.

It is preferable to deal automatically without depending on manpower.
2018-07-12 21:29:48 +09:00

41 lines
1.1 KiB
Ruby

# frozen_string_literal: true
namespace :log do
##
# Truncates all/specified log files
# ENV['LOGS']
# - defaults to all environments 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)
end
end
def log_files
if ENV["LOGS"] == "all"
FileList["log/*.log"]
elsif ENV["LOGS"]
log_files_to_truncate(ENV["LOGS"])
else
log_files_to_truncate(all_environments.join(","))
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
end
def all_environments
Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
end
end