Skip to content

Instantly share code, notes, and snippets.

@ffeldhaus
Created March 28, 2012 10:44
Show Gist options
  • Save ffeldhaus/2225345 to your computer and use it in GitHub Desktop.
Save ffeldhaus/2225345 to your computer and use it in GitHub Desktop.
Logging with ActiveSupport
require 'sinatra'
require 'active_support'
require 'logger'
class SinatraTest < Sinatra::Application
class TestClass
def initialize
ActiveSupport::Notifications.instrument("log", :level => Logger::INFO, :message => "my message" )
end
end
before do
@log_subscriber = ActiveSupport::Notifications.subscribe("log") do |name, start, finish, id, payload|
logger.log(payload[:level],payload[:message])
end
end
after do
ActiveSupport::Notifications.unsubscribe(@log_subscriber)
end
get '/' do
TestClass.new
end
run!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment