Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Sinatra standard output

Tags:

ruby

sinatra

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?

like image 837
ecnepsnai Avatar asked May 27 '15 00:05

ecnepsnai


1 Answers

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.

like image 190
matt Avatar answered Sep 28 '22 19:09

matt