有人可以解释一下这种和平的代码是如何工作的,尤其是日志过滤器部分。我想log_attributes_filter
从我调用的机架文件中分配,该use MongodbLogger::RackMiddleware
怎么做?
# Rack middleware for mounted rack app (e.g Grape)
module MongodbLogger
class RackMiddleware
@@log_attributes_filter = nil
def self.log_attributes_filter=(filter)
@@log_attributes_filter = filter
end
def initialize(app)
@app = app
end
def call(env)
request = ::Rack::Request.new env
path = request.path.split('/')
log_attrs = {
params: request.params
}
log_attrs = @@log_attributes_filter.call(log_attrs) if @@log_attributes_filter
logger.mongoize(log_attrs) do
return @app.call(env)
end
end
end
end
在我简单地将它用作之前use MongodbLogger::RackMiddleware
,但现在我想过滤一些参数,我应该如何正确分配@@log_attributes_filter
?