Skip to content

Instantly share code, notes, and snippets.

@timmatheson
Created September 3, 2010 23:32
Show Gist options
  • Save timmatheson/564719 to your computer and use it in GitHub Desktop.
Save timmatheson/564719 to your computer and use it in GitHub Desktop.
HerokuLogger Class, allows you to tail the heroku logs through hackery.
class HerokuLogger
def initialize
@keep_processing = true
@log = nil
stop_tailing = Proc.new do
puts "---------------------- Terminating ------------------------"
@keep_processing = false
end
Signal.trap("INT", stop_tailing)
Signal.trap("TERM", stop_tailing)
end
def process
while @keep_processing
if fetch_log
print @log
else
sleep(2)
end
end
end
def fetch_log
log = `heroku logs`
if new_output?(log)
@log = log
return true
end
false
end
def new_output?(data)
data != @log
end
def self.process
new.process
end
end
HerokuLogger.process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment