Disable Sinatra standard output

六月ゝ 毕业季﹏ 提交于 2019-12-23 13:07:55

问题


For security reasons I don't wish to have Sinatra print every URL its requested in standard output, I've tried using set :logging, false as suggested in this answer using:

class SweetAppName< Sinatra::Base
    set :show_exceptions, false
    set :environment, :production
    set :logging, false

However when I run the app using rackup and thin, I still see the request logged to the terminal:

127.0.0.1 - - [26/May/2015:09:32:34 -0700] "GET /not-a-real-url HTTP/1.0" 404 - 0.0452

How can I turn these off?


回答1:


If you start your app with rackup, Rack will add some middleware, including logging. You can prevent this by using the quiet option (-q or --quiet) to rackup, i.e. from the command line:

$ rackup -q

You can include this option in your config.ru if you want, so you don’t have to remember typing it every time you start your app. The first line that starts with #\ is parsed as options, so you can have a config.ru like this:

#\ --quiet

# other middleware etc...
run SweetAppName

If you use the classic Sinatra app style you will need to add the set :logging, false line, otherwise Sinatra will add its own logging. With the modular style (like you are using in the question) this setting defaults to false so you shouldn’t need it.



来源:https://stackoverflow.com/questions/30471322/disable-sinatra-standard-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!