Where does RACK log to?

14,397

Solution 1

It depends. Many developers define their app log file to app/servername.log or just to the current path where the Rack app is loaded.

Yes you can change it's path.

Usually you get a config.ru file with something like:

    log = File.new("sinatra.log", "a+")
    $stdout.reopen(log)
    $stderr.reopen(log)

    # optionally to sync logs while the server is running
    $stderr.sync = true
    $stdout.sync = true

and/or

    configure do
      LOGGER = Logger.new("sinatra.log")
      enable :logging, :dump_errors
      set :raise_errors, true
    end

in this case the log file is located under appdir/sinatra.log. But remember this code can be anywhere in your Rack app, so please seek for "log" in your application directory.

    $ cd projectname
    $ grep -ri 'log' *

have fun and post here your config.ru and/or the mainprojectfile.rb.

Solution 2

The line of LOGGER = Logger.new("sinatra.log") in @include's answer above did not work for me.

However, an alternative listed here (along with some helpful explanations) worked for me, tested with ruby 2.5.3 and sinatra 2.0.1.

For additional info, that alternative is based on the structure presented in a Sinatra recipe.

Share:
14,397

Related videos on Youtube

Moodie
Author by

Moodie

Updated on April 15, 2022

Comments

  • Moodie
    Moodie about 2 years

    I am running a sinatra app through RACK.

    To which file does the activity get logged ? Also how can I set the log file path ?

  • Moodie
    Moodie about 14 years
    Hi Francisco. Yep, this worked perfect for me. log_path = "<path-to-log-file>" LOGGER = Logger.new(log_path, "daily") log = File.new(log_path, "a+") STDOUT.reopen(log) STDERR.reopen(log)
  • David Tuite
    David Tuite over 12 years
    @include: Is there a way that I can make the production and development envirnments log to files but make test log to the terminal? It seems that when I reopen $stdout and $stderr, it redirects test output to files also.
  • fguillen
    fguillen over 10 years
    Reopening STDOUT can make Passenger to not start: github.com/phusion/passenger/wiki/…