新手问题 grape 把请求日志存在一个单独的文件里

yakjuly · 2012年12月01日 · 3996 次阅读
module APIBase
  extend ActiveSupport::Concern

  included do
    default_format :json
    logger Logger.new(Rails.root.join("log/grape.log"))
    version 'v1', :strict => true, :using => :path

    http_basic do |user, password|
      user == APP_CONFIG[:basic_user] && password == APP_CONFIG[:basic_password]
    end
  end
end

1 grape 的请求日志一直都是默认存在 log/production.log中。 怎样才能把 所有请求到 API 的日志 都放在一个单独的文件中? 这里设置的 log/grape.log并不会记录 "Started GET "/api/v1/posts.json" for 127.0.0.1 at 2012-12-01 12:49:22 +0800".

2 production 日志中并没有体现返程结果,貌似日志到一半就被截断了。 验证失败返回的结果。我认为需要"Completed 401 Unauthorized in 1ms" 类似这种信息。

3 用户 http basic 验证失败的时候,怎么样能抓到该错误后再返回结果。因为我需要做一个 ip 限制,如果一个 ip 验证失败了多次 就禁止该 IP 地址访问。写了 rescue_from 也没有用。另外还有没有办法能 before :http_basic?

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号