Snippet: Rack::CommonLogger in Sinatra

February 5, 2010

It’s been a little while. I’ve been completely swamped with school and work, but I realized there wasn’t really any code samples I could find for using Rack::CommonLogger in Sinatra. Solution after the jump.

If you wanted to log stuff like you would in rails and sinatra, here would be a very clean way to do it.

configure do
  Dir.mkdir('log') unless File.exists?('log')

configure :test do
  use Rack::CommonLogger,'log/test.log', 'w')

configure :development do
  use Rack::CommonLogger,'log/development.log', 'w')

configure :production do
  use Rack::CommonLogger,'log/production.log', 'w')

More updates to come once I get out of midterm hell next week.