7

I have a Sinatra::Base webservice which I want to start from a command line Ruby program, so I have this:

# command line program file
require 'mymodule/server'

puts "Running on 0.0.0.0:4567, debugging to STDOUT..."

MyModule::Server.run! bind: '0.0.0.0', port: 4567, environment: :production

This works as expected but it throws out:

$ myscript
Running on 0.0.0.0:4567, debugging to STDOUT...

== Sinatra/1.3.1 has taken the stage on 4567 for production with backup from Thin
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567, CTRL+C to stop

127.0.0.1 - - [23/Dec/2011 18:44:55] "POST /images HTTP/1.1" 200 360 0.0133
...

And I want it to be silent, and let me output what I want. For example, if I start it not daemonized I want to just see some message from the command line program and the log output, something like:

$ myscript
Running on 0.0.0.0:4567, debugging to STDOUT...
127.0.0.1 - - [23/Dec/2011 18:44:55] "POST /images HTTP/1.1" 200 360 0.0133
...

Also would like to silently shutdown it, hiding:

== Sinatra has ended his set (crowd applauds)

One last question, is this the best option to start a sinatra app with thin from inside an application code(ruby script in this case)?

João Pereira
  • 561
  • 4
  • 18

1 Answers1

2

You can turn off Sinatra logging with

set :logging, false

http://www.sinatrarb.com/configuration.html

As far as whether or not this is the best way to start a sinatra app... You might want to look at the "foreman" gem, and the "Procfile" (which Heroku.com uses) as an example:

http://ddollar.github.com/foreman/

GroovyCakes
  • 361
  • 2
  • 12
  • If using SinatraBase, you have to do it inside the class declaration... http://www.sinatrarb.com/intro.html#Sinatra::Base%20-%20Middleware,%20Libraries,%20and%20Modular%20Apps – GroovyCakes Feb 20 '13 at 21:47
  • You could also try the enable/disable-style setting of options – GroovyCakes Feb 20 '13 at 21:49
  • 2
    You can see https://github.com/sinatra/sinatra/blob/faf2efc670bf4c6076c26d5234c577950c19b699/lib/sinatra/base.rb#L1415 that it's not possible to silence the shutdown (or startup) messages (unless you reopen stderr, but seems inadvisable). – mxcl Mar 17 '14 at 18:11