Created
March 28, 2012 10:44
-
-
Save ffeldhaus/2225345 to your computer and use it in GitHub Desktop.
Logging with ActiveSupport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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