Last Updated: February 25, 2016
·
1.788K
· gus

Logging exceptions on Sinatra

Simply debugging an application in Sinatra it's a bit of a headache. Logging in particular was being kinda troublesome in our Passenger stack.

I've found out the following approach to solve the logging issue for us.

log_file = File.new("#{settings.root}/log/#{settings.environment}.log", 'a+')

STDOUT.reopen(log_file)
STDERR.reopen(log_file)

STDOUT.sync = true
STDERR.sync = true

Worth checking, the sinatra recipes website.