Sha256: 75d9ef366f4cdf822012c768403ab3bae17aaad038049a6e54764dc1fadd4a5e

Contents?: true

Size: 955 Bytes

Versions: 33

Compression:

Stored size: 955 Bytes

Contents

namespace :log do
  
  ## 
  # Truncates all/specified log files
  # ENV['LOGS'] 
  #   - defaults to standard environment 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("development,test,production")
    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
end

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
railties-5.0.7.2 lib/rails/tasks/log.rake
railties-5.0.7.1 lib/rails/tasks/log.rake
railties-5.0.7 lib/rails/tasks/log.rake
railties-5.0.6 lib/rails/tasks/log.rake
railties-5.0.6.rc1 lib/rails/tasks/log.rake
railties-5.0.5 lib/rails/tasks/log.rake
railties-5.0.5.rc2 lib/rails/tasks/log.rake
railties-5.0.5.rc1 lib/rails/tasks/log.rake
railties-5.0.4 lib/rails/tasks/log.rake
railties-5.0.4.rc1 lib/rails/tasks/log.rake
railties-5.0.3 lib/rails/tasks/log.rake
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/railties-5.0.2/lib/rails/tasks/log.rake
railties-5.0.2 lib/rails/tasks/log.rake
railties-5.0.2.rc1 lib/rails/tasks/log.rake
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/log.rake
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/log.rake
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/log.rake
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/log.rake
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/log.rake
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/log.rake