九月
13

这是一个很容易被忽视的问题,尤其是对于新入门的Rails程序员。默认设置时,Rail程序在运行的时候,提供了很详细的Log,Log文件快速增长会占用大量的服务器空间,文件一般保存在rails app/log/目录下。

Log Level

Rails可以通过选择不同的log lever来控制log文件的输出,可以使用的log lever有:debug, :info, :warn, :error, :fatal. :debug level提供最详细的log, 可以将每一条sql都记录下来。:info level是production环境下的默认设置,不会写出sql的执行情况,但也会很详细,如果是ActiveMailer,它会记录下每封信的内容,Log文件内容就是快速增长。为了避免Log把空间塞满的情况发生,要注意定期清除Log,另外是选择:warn level等log level, 只记录重要的信息.

设置方法:

在/config/environment.rb文件中可以设置以下选项

config.log_level = :debug

如果只希望在production环境下,输入少量的log, 则只需要在config/environments/production.rb中增加一项(我就是这样设置的)

config.log_level = :warn

参考资料:HowtoConfigureLogging in Ruby on Rails

 

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg

Tags:

No Responses

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>