在开发模式中,开发环境日志会越来越大,所以需要设置自动清理,省内存。

在 config/initializers中新建一个文件 clear_blog.rb

编写如下代码

 1 if Rails.env.development?
 2   MAX_LOG_SIZE = 10.megabytes
 3 
 4   logs = [ File.join(Rails.root, 'log', 'development.log'), File.join(Rails.root, 'log', 'test.log') ]
 5 
 6   logs.each do |log|
 7     if File.size?(log).to_i > MAX_LOG_SIZE
 8       $stdout.puts "Removing Log: #{log}"
 9       `rm #{log}`
10     end
11   end
12 end

FROM : guanMac

相关文章:

  • 2021-10-09
  • 2022-01-15
  • 2022-12-23
  • 2021-06-29
  • 2021-09-29
  • 2021-07-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2023-01-13
  • 2021-10-10
相关资源
相似解决方案