Ruby on Rails 日志文件太大
我偶然发现我的rails3.1日志文件超级大,大约21mb。 就尺寸而言,这是正常的吗?生产环境中的日志文件是什么样的? 另外,我可以去掉日志吗?谢谢
I stumbled to learn that my rails3.1 log file is super large, around 21mb.
Is this, in terms of size normal? What the log file would like in the production environment?
Besides, can I get rid of the log?thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
Rails 应用程序的
log
文件夹包含与每个标准环境相对应的三个日志文件。随着时间的推移,日志文件可能会变得非常大。提供了rake 任务
以允许轻松清除日志文件。The
log
folder of your Rails application holds three log files corresponding to each of the standard environments. Log files can grow very large over time. Arake task
is provided to allow the easy clearing of the log files.您只需删除该文件即可!
如果日志不存在,Rails 将创建一个新日志。
显然,如果文件很重要,请保存/备份该文件,但通常情况下并不重要。
如果您想将备份文件保留在同一驱动器上但仍节省空间,您还可以压缩备份文件(然后删除源文件)。
要自动轮换日志文件(最佳长期解决方案),请使用日志轮换,如下所述:
Ruby on Rails 生产日志轮换
然后你就可以设置它并忘记它!
要实际更改记录的内容,请参阅:
http: //dennisreimann.de/blog/silencing-the-rails-log-on-a-per-action-basis/
you can just delete the file!
Rails will create a new log if one doesn't exist.
Obviously save / backup the file if it's important, but usually it's not.
You can also zip the backuped up file (and then delete the source) if you want to keep it on the same drive but still save space.
To automatically rotate log files (the best long-term solution) use log rotate as described here:
Ruby on Rails production log rotation
then you can set it and forget it!
To actually change what gets logged see:
http://dennisreimann.de/blog/silencing-the-rails-log-on-a-per-action-basis/
根据文档,如果您想限制日志文件夹的大小,请将其放入您的“development.rb”文件中:
这样,您的日志文件将永远不会增长超过 50Mb。您可以根据自己的喜好更改尺寸。第二个参数中的“1”表示将保留 1 个历史日志文件,因此您将拥有最多 100Mb 的日志 – 当前日志和前一个 50Mb 的日志块。
According to the documentation, if you want to limit the size of the log folder, put this in your 'development.rb'-file:
With this, your log files will never grow bigger than 50Mb. You can change the size to your own preference. The ‘1’ in the second parameter means that 1 historic log file will be kept, so you’ll have up to 100Mb of logs – the current log and the previous chunk of 50Mb.
我自动清除每台服务器上的开发日志,从 config/initializers/clear_development_log.rb 开始:
I automatically clear the logs in development on each server start with
config/initializers/clear_development_log.rb
:您可能想要使用
logrotate
。看看这个问题的答案:Ruby on Rails 生产日志轮换。You may want to use
logrotate
. Have a look at the answer to this question: Ruby on Rails production log rotation.是的,您可以使用这样的语法:
示例:
它不仅用于 Rails 日志,您还可以使用任何与 Rails 一起运行的服务的日志文件,例如:rpush log,...
Yes, You can using syntax like this:
Example:
It not only using for Rails log, you can using log file of any services run with rails, such as: rpush log, ...
如果您不喜欢等待 rake log:clear 加载其环境而只想即时清除一个日志,您可以执行以下操作:(
这允许日志在应用程序正在运行,而 rm log/mylog.log 需要重新启动应用程序。)
If you don't like waiting for
rake log:clear
to load its environment and only want to clear one log on the fly, you can do the following:(This allows the log to stay online while the app is running, whereas
rm log/mylog.log
would require restarting the app.)config.logger = ActiveSupport::Logger.new(nil)
做到了这一点并完全禁用记录到文件(保留控制台输出)。config.logger = ActiveSupport::Logger.new(nil)
does the trick and completely disables logging to a file (console output is preserved).一个公平的妥协,在初始化器中:
A fair compromise, in an initializer:
现在可以在最新版本的 Rails 中配置
log_file_size
。这些信息可能对您有用。参考: https://guides.rubyonrails.org/configuring.html#配置日志文件大小
It is now possible to configure the
log_file_size
in the latest version of Rails. This information may be useful for you.REF: https://guides.rubyonrails.org/configuring.html#config-log-file-size