Skip to content

Instantly share code, notes, and snippets.

@rkh
Forked from ffeldhaus/gist:2225345
Created March 28, 2012 11:43
Show Gist options
  • Save rkh/2225573 to your computer and use it in GitHub Desktop.
Save rkh/2225573 to your computer and use it in GitHub Desktop.
Logging with ActiveSupport
require 'sinatra'
require 'active_support'
require 'logger'
class SinatraTest < Sinatra::Application
module RedirectedLogger
def self.logger=(value)
Thread.current['sinatra.logger'] = value
end
def logger
Thread.current['sinatra.logger'] ||= Rack::NullLogger.new(nil)
end
end
class TestClass
include RedirectedLogger
def initialize
logger.info "my message"
end
end
before { RedirectedLogger.logger = logger }
get('/') { TestClass.new }
run!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment