Skip to content

Instantly share code, notes, and snippets.

@jbgutierrez jbgutierrez/lazy-logger.rb
Last active Oct 29, 2015

Embed
What would you like to do?
Lazy logging errors to bost performace
# Meassure the difference:
# $ ab -r -n 10 http://127.0.0.1:4567/ | grep "Requests per second"
require 'sinatra'
require 'logger'
ERRLOG = Logger.new "#{__FILE__}.err"
ERRQ = Queue.new
Thread.new do
loop do
while msg = ERRQ.pop do
ERRLOG.error msg
end
sleep 2
end
end
disable :logging
get '/' do
ERRQ << "That thing happened again"
send_file __FILE__, disposition: 'inline'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.