原创作者: hideto   阅读:1178次   评论:0条   更新时间:2011-05-26    
Rails在controller里自带了logger,我们可以用来做debug:
def show
  @cart = current_cart
  logger.debug "Hello world! #{@cart.to_yaml}"
  # debug, info, warn, error, fatal
end


我们可以在environment.rb里配置Logger的消息格式:
class Logger
  def format_message(level, time, progname, msg)
    "#{time.to_s(:db)} #{level} -- #{msg}\n"
  end
end


我们还可以在environments/production.rb里配置log_level
config.log_level = :debug


使用rake log:clear可以清空旧日志

在.irbrc里也可以设置Logger:
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
  require 'logger'
  Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
end

这样在script/console里的Model操作就会直接in place显示在console里
评论 共 0 条 请登录后发表评论

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics