Sinatra:三个原木

Sinatra:三个原木

问题描述:

我正在使用一个非常简单的 Sinatra 应用,效果很好.但是,每条日志消息都会重复 3 次.我可以通过禁用 Sinatra 日志记录将其减少到两个

I'm using a very simple Sinatra app that works well. However, every log message is repeated three times. I can bring that down to two by disabling the Sinatra logging with

disable :logging

但我还有两个.消息略有不同,所以我认为它们来自 Rack 和堆栈中的其他地方.

but I still have two. The messages are slightly different, so I gather they are coming from Rack and somewhere else in the stack too.

如何完全禁用成功 Web 请求的日志记录?

How do I completely disable logging of successful web requests?

Rack 正在添加自己的日志记录作为中间件尝试运行

Rack is adding own logging as a middleware try to run

rackup -E none

这会删除一个日志条目.第二个是您已经禁用的 sinatra 本机.如果我没记错的话,第三个是 Rack::Lint 日志记录.一般方法是像

This removes one log entry. The second one is sinatra native which you've already disable. And the third one is Rack::Lint logging if I remember correctly. General approach is to restructure your app like

app.rb

require 'sinatra/base'
class App < Sinatra::Base
  get '/' do
    "hello"
  end
end

config.ru

require 'myapp'
run MyApp 

或者你可以在机架外运行应用程序

Or you can run app outside rack

if __FILE__ == $0
  App.run!
end